Skip to content

Commit

Permalink
Fix build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn committed Sep 17, 2020
1 parent d08b72c commit 1996edc
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
8 changes: 4 additions & 4 deletions eng/build.yml
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/WinSW.Core/Configuration/XmlServiceConfig.cs
Expand Up @@ -241,7 +241,7 @@ public List<string> ExtensionIds
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;
Expand All @@ -264,12 +264,12 @@ public List<string> ExtensionIds

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("\""))
{
Expand Down Expand Up @@ -471,7 +471,7 @@ public override string[] ServiceDependencies
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;
Expand Down Expand Up @@ -588,8 +588,8 @@ public override SC_ACTION[] FailureActions
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,
Expand Down Expand Up @@ -682,13 +682,13 @@ public override ProcessPriorityClass Priority

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);
Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Core/Extensions/WinSWExtensionManager.cs
Expand Up @@ -63,7 +63,7 @@ public void FireOnWrapperStarted()
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
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/WinSW.Core/WinSW.Core.csproj
@@ -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>
Expand All @@ -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" />
Expand All @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Plugins/WinSW.Plugins.csproj
@@ -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>
Expand Down
2 changes: 2 additions & 0 deletions src/WinSW.Tests/Util/InterProcessCodeCoverageSession.cs
Expand Up @@ -48,8 +48,10 @@ internal InterProcessCodeCoverageSession(string serviceName)
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);

Expand Down
10 changes: 5 additions & 5 deletions src/WinSW.Tests/WinSW.Tests.csproj
@@ -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>

Expand All @@ -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>
Expand All @@ -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>

Expand Down
20 changes: 10 additions & 10 deletions src/WinSW/WinSW.csproj
Expand Up @@ -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>
Expand All @@ -16,23 +16,23 @@
<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>

<ItemGroup>
<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>
Expand All @@ -42,28 +42,28 @@
<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" />

</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>
Expand Down Expand Up @@ -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>

Expand Down

0 comments on commit 1996edc

Please sign in to comment.