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 projects: src\WinSW.sln
arguments: -c $(BuildConfiguration) -p:Version=$(BuildVersion) arguments: -c $(BuildConfiguration) -p:Version=$(BuildVersion)
- script: | - 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-windows -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-windows -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-windows -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-x86 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
displayName: Build displayName: Build
- task: DotNetCoreCLI@2 - task: DotNetCoreCLI@2
displayName: Test displayName: Test

View File

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

View File

@ -63,7 +63,7 @@ namespace WinSW.Extensions
catch (ExtensionException ex) catch (ExtensionException ex)
{ {
Log.Fatal("onWrapperStarted() handler failed for " + ext.Value.DisplayName, 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"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net461;net5.0</TargetFrameworks> <TargetFrameworks>net461;net5.0-windows</TargetFrameworks>
<LangVersion>preview</LangVersion> <LangVersion>preview</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -15,14 +15,14 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" /> <PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.Diagnostics.EventLog" Version="4.7.0" /> <PackageReference Include="System.Diagnostics.EventLog" Version="4.7.0" />
<PackageReference Include="System.Security.AccessControl" Version="4.7.0" /> <PackageReference Include="System.Security.AccessControl" Version="4.7.0" />
</ItemGroup> </ItemGroup>
<!-- error NU1605: Detected package downgrade: log4net 2.0.8 --> <!-- 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.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" /> <PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" 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" /> <PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'"> <ItemGroup Condition="'$(TargetFramework)' != 'net5.0-windows'">
<PackageReference Include="System.Memory" Version="4.5.4" /> <PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> <PackageReference Include="System.ValueTuple" Version="4.5.0" />
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />

View File

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

View File

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

View File

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

View File

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