Fix build warnings

pull/685/head
NextTurn 2020-09-13 00:00:00 +08:00 committed by Next Turn
parent d08b72ceb3
commit 1996edc6b4
8 changed files with 37 additions and 35 deletions

View File

@ -40,10 +40,10 @@ jobs:
projects: src\WinSW.sln
arguments: -c $(BuildConfiguration) -p:Version=$(BuildVersion)
- script: |
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x64 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x86 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x64 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x86 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0-windows -r win-x64 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0-windows -r win-x86 -p:Version=$(BuildVersion)
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0-windows -r win-x64 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0-windows -r win-x86 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
displayName: Build
- task: DotNetCoreCLI@2
displayName: Test

View File

@ -241,7 +241,7 @@ namespace WinSW
List<string> result = new List<string>(extensions.Count);
for (int i = 0; i < extensions.Count; i++)
{
result.Add(XmlHelper.SingleAttribute<string>((XmlElement)extensions[i], "id"));
result.Add(XmlHelper.SingleAttribute<string>((XmlElement)extensions[i]!, "id"));
}
return result;
@ -264,12 +264,12 @@ namespace WinSW
StringBuilder arguments = new StringBuilder();
XmlNodeList argumentNodeList = this.dom.SelectNodes("//" + tagName);
XmlNodeList argumentNodeList = this.dom.SelectNodes("//" + tagName)!;
for (int i = 0; i < argumentNodeList.Count; i++)
{
arguments.Append(' ');
string token = Environment.ExpandEnvironmentVariables(argumentNodeList[i].InnerText);
string token = Environment.ExpandEnvironmentVariables(argumentNodeList[i]!.InnerText);
if (token.StartsWith("\"") && token.EndsWith("\""))
{
@ -471,7 +471,7 @@ namespace WinSW
string[] serviceDependencies = new string[nodeList.Count];
for (int i = 0; i < nodeList.Count; i++)
{
serviceDependencies[i] = nodeList[i].InnerText;
serviceDependencies[i] = nodeList[i]!.InnerText;
}
return serviceDependencies;
@ -588,8 +588,8 @@ namespace WinSW
SC_ACTION[] result = new SC_ACTION[childNodes.Count];
for (int i = 0; i < childNodes.Count; i++)
{
XmlNode node = childNodes[i];
string action = node.Attributes["action"].Value;
XmlNode node = childNodes[i]!;
string action = node.Attributes!["action"]?.Value ?? throw new InvalidDataException("'action' is missing");
SC_ACTION_TYPE type = action switch
{
"restart" => SC_ACTION_TYPE.SC_ACTION_RESTART,
@ -682,13 +682,13 @@ namespace WinSW
private Dictionary<string, string> LoadEnvironmentVariables()
{
XmlNodeList nodeList = this.dom.SelectNodes("//env");
XmlNodeList nodeList = this.dom.SelectNodes("//env")!;
Dictionary<string, string> environment = new Dictionary<string, string>(nodeList.Count);
for (int i = 0; i < nodeList.Count; i++)
{
XmlNode node = nodeList[i];
string key = node.Attributes["name"].Value;
string value = Environment.ExpandEnvironmentVariables(node.Attributes["value"].Value);
XmlNode node = nodeList[i]!;
string key = node.Attributes!["name"]?.Value ?? throw new InvalidDataException("'name' is missing");
string value = Environment.ExpandEnvironmentVariables(node.Attributes["value"]?.Value ?? throw new InvalidDataException("'value' is missing"));
environment[key] = value;
Environment.SetEnvironmentVariable(key, value);

View File

@ -63,7 +63,7 @@ namespace WinSW.Extensions
catch (ExtensionException ex)
{
Log.Fatal("onWrapperStarted() handler failed for " + ext.Value.DisplayName, ex);
throw ex; // Propagate error to stop the startup
throw; // Propagate error to stop the startup
}
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;net5.0</TargetFrameworks>
<TargetFrameworks>net461;net5.0-windows</TargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -15,14 +15,14 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.7.0" />
<PackageReference Include="System.Security.AccessControl" Version="4.7.0" />
</ItemGroup>
<!-- error NU1605: Detected package downgrade: log4net 2.0.8 -->
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
@ -32,7 +32,7 @@
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<Reference Include="System.ServiceProcess" />

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;net5.0</TargetFrameworks>
<TargetFrameworks>net461;net5.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -48,8 +48,10 @@ namespace WinSW.Tests.Util
hr = client.SetEventCallbacks(this);
AssertEx.Succeeded(hr);
#pragma warning disable CA1416 // Validate platform compatibility
IntPtr pointer = Marshal.GetIUnknownForObject(client);
Assert.Equal(1, Marshal.Release(pointer));
#pragma warning restore CA1416 // Validate platform compatibility
target = DataTarget.CreateFromDbgEng(pointer);

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net471;net5.0</TargetFrameworks>
<TargetFrameworks>net471;net5.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
@ -20,7 +20,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<PackageReference Include="System.Reflection.Metadata" Version="1.8.1" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
@ -39,11 +39,11 @@
<Target Name="Copy" BeforeTargets="AfterBuild">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net5.0\WinSW.runtimeconfig*.json" />
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net5.0-windows\WinSW.runtimeconfig*.json" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net461\System.ValueTuple.dll" />
</ItemGroup>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;net5.0</TargetFrameworks>
<TargetFrameworks>net461;net5.0-windows</TargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -16,11 +16,11 @@
<Copyright>Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees, Inc., Oleg Nenashev and other contributors</Copyright>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0' AND '$(RuntimeIdentifier)' != ''">
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows' AND '$(RuntimeIdentifier)' != ''">
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' != 'net5.0'">
<PropertyGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<ILMergeVersion>3.0.41</ILMergeVersion>
</PropertyGroup>
@ -28,11 +28,11 @@
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20303.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.7.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<PackageReference Include="ilmerge" Version="$(ILMergeVersion)" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
@ -42,20 +42,20 @@
<ProjectReference Include="..\WinSW.Plugins\WinSW.Plugins.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<ProjectReference Include="..\WinSW.Tasks\WinSW.Tasks.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Target Name="PublishCoreZip" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0' and '$(IncludeNativeLibrariesInSingleFile)' != 'true'">
<Target Name="PublishCoreZip" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0-windows' and '$(IncludeNativeLibrariesInSingleFile)' != 'true'">
<MakeDir Directories="$(ArtifactsPublishDir)" />
<ZipDirectory SourceDirectory="$(PublishDir)" DestinationFile="$(ArtifactsPublishDir)WinSW.NETCore.$(PlatformTarget).zip" Overwrite="true" />
</Target>
<Target Name="PublishCoreExe" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0' and '$(IncludeNativeLibrariesInSingleFile)' == 'true'">
<Target Name="PublishCoreExe" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0-windows' and '$(IncludeNativeLibrariesInSingleFile)' == 'true'">
<MakeDir Directories="$(ArtifactsPublishDir)" />
<Copy SourceFiles="$(PublishDir)$(TargetName).exe" DestinationFiles="$(ArtifactsPublishDir)WinSW.NETCore.$(PlatformTarget).exe" />
@ -63,7 +63,7 @@
</Target>
<!-- Merge plugins and other DLLs into the executable -->
<Target Name="Merge" BeforeTargets="AfterBuild" Condition="'$(TargetFramework)' != 'net5.0'">
<Target Name="Merge" BeforeTargets="AfterBuild" Condition="'$(TargetFramework)' != 'net5.0-windows'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<TargetFrameworkSuffix>NET461</TargetFrameworkSuffix>
@ -95,7 +95,7 @@
</Target>
<UsingTask TaskName="WinSW.Tasks.Trim" AssemblyFile="$(ArtifactsBinDir)WinSW.Tasks\$(Configuration)\net461\WinSW.Tasks.dll" />
<Target Name="Trim" AfterTargets="Merge" Condition="'$(TargetFramework)' != 'net5.0'">
<Target Name="Trim" AfterTargets="Merge" Condition="'$(TargetFramework)' != 'net5.0-windows'">
<Trim Path="$(ArtifactsPublishDir)WinSW.$(TargetFrameworkSuffix).exe" />
</Target>