Skip to content

Commit

Permalink
Upgrade to .NET 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn committed Aug 20, 2020
1 parent dcf3013 commit 3bfa46f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 28 deletions.
8 changes: 4 additions & 4 deletions eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
projects: src\WinSW.sln
arguments: -c $(BuildConfiguration) -p:Version=$(BuildVersion)
- script: |
dotnet publish -c $(BuildConfiguration) -f netcoreapp3.1 -r win-x64 src\WinSW\WinSW.csproj -p:Version=$(BuildVersion)
dotnet publish -c $(BuildConfiguration) -f netcoreapp3.1 -r win-x86 src\WinSW\WinSW.csproj -p:Version=$(BuildVersion)
dotnet publish -c $(BuildConfiguration) -f netcoreapp3.1 -r win-x64 src\WinSW\WinSW.csproj -p:PublishSingleFile=true -p:Version=$(BuildVersion)
dotnet publish -c $(BuildConfiguration) -f netcoreapp3.1 -r win-x86 src\WinSW\WinSW.csproj -p:PublishSingleFile=true -p:Version=$(BuildVersion)
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
displayName: Build
- task: DotNetCoreCLI@2
displayName: Test
Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Core/Configuration/ServiceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class ServiceConfig

public abstract string Executable { get; }

public virtual string ExecutablePath => Process.GetCurrentProcess().MainModule.FileName;
public virtual string ExecutablePath => Process.GetCurrentProcess().MainModule!.FileName!;

public virtual bool HideWindow => false;

Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Core/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public async Task PerformAsync()
}
catch (WebException e)
{
if (supportsIfModifiedSince && ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotModified)
if (supportsIfModifiedSince && ((HttpWebResponse?)e.Response)?.StatusCode == HttpStatusCode.NotModified)
{
Logger.Info($"Skipped downloading unmodified resource '{this.From}'");
}
Expand Down
8 changes: 4 additions & 4 deletions src/WinSW.Core/WinSW.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;net5.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -15,13 +15,13 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.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)' == 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<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 @@ -31,7 +31,7 @@
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<Reference Include="System.ServiceProcess" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Plugins/WinSW.Plugins.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;net5.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/WinSW.Tests/WinSW.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Target Name="Copy" BeforeTargets="AfterBuild">

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp5.0'">
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\netcoreapp3.1\WinSW.runtimeconfig*.json" />
<_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net5.0\WinSW.runtimeconfig*.json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp5.0'">
Expand Down
10 changes: 5 additions & 5 deletions src/WinSW/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static string ExecutablePath
}

using Process current = Process.GetCurrentProcess();
return current.MainModule.FileName;
return current.MainModule!.FileName!;
}
}

Expand Down Expand Up @@ -463,7 +463,7 @@ void PromptForCredentialsConsole()
if (username is null)
{
Console.Write("Username: ");
username = Console.ReadLine();
username = Console.ReadLine()!;
}

if (password is null && !IsSpecialAccount(username))
Expand Down Expand Up @@ -798,7 +798,7 @@ void Test(string? pathToConfig, bool noElevate, bool noBreak)
_ = evt.WaitOne();
Console.CancelKeyPress -= CancelKeyPress;

void CancelKeyPress(object sender, ConsoleCancelEventArgs e)
void CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
{
e.Cancel = true;
evt.Set();
Expand Down Expand Up @@ -968,14 +968,14 @@ static void Elevate(bool noElevate)
{
UseShellExecute = true,
Verb = "runas",
FileName = current.MainModule.FileName,
FileName = current.MainModule!.FileName!,
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden,
};

try
{
using Process elevated = Process.Start(startInfo);
using Process elevated = Process.Start(startInfo)!;

elevated.WaitForExit();
Environment.Exit(elevated.ExitCode);
Expand Down
22 changes: 13 additions & 9 deletions src/WinSW/WinSW.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;net5.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -15,19 +15,23 @@
<Copyright>Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees, Inc., Oleg Nenashev and other contributors</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0' AND '$(RuntimeIdentifier)' != ''">
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ILMergeVersion>3.0.40</ILMergeVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20303.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.7.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<PackageReference Include="ilmerge" Version="$(ILMergeVersion)" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
Expand All @@ -37,28 +41,28 @@
<ProjectReference Include="..\WinSW.Plugins\WinSW.Plugins.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ProjectReference Include="..\WinSW.Tasks\WinSW.Tasks.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

<Target Name="PublishCoreZip" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'netcoreapp3.1' and '$(PublishSingleFile)' != 'true'">
<Target Name="PublishCoreZip" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0' 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)' == 'netcoreapp3.1' and '$(PublishSingleFile)' == 'true'">
<Target Name="PublishCoreExe" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0' 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)' != 'netcoreapp3.1'">
<Target Name="Merge" BeforeTargets="AfterBuild" Condition="'$(TargetFramework)' != 'net5.0'">

<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<TargetFrameworkSuffix>NET461</TargetFrameworkSuffix>
Expand Down Expand Up @@ -90,7 +94,7 @@
</Target>

<UsingTask TaskName="WinSW.Tasks.Trim" AssemblyFile="$(ArtifactsBinDir)WinSW.Tasks\$(Configuration)\net461\WinSW.Tasks.dll" />
<Target Name="Trim" AfterTargets="Merge" Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<Target Name="Trim" AfterTargets="Merge" Condition="'$(TargetFramework)' != 'net5.0'">
<Trim Path="$(ArtifactsPublishDir)WinSW.$(TargetFrameworkSuffix).exe" />
</Target>

Expand Down
4 changes: 2 additions & 2 deletions src/WinSW/WrapperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ private void OnMainProcessExited(Process process)
/// </summary>
private Process StartProcess(string executable, string? arguments, LogHandler? logHandler = null, Action<Process>? onExited = null)
{
var startInfo = new ProcessStartInfo(executable, arguments)
var startInfo = new ProcessStartInfo(executable, arguments ?? string.Empty)
{
UseShellExecute = false,
WorkingDirectory = this.config.WorkingDirectory,
Expand Down Expand Up @@ -572,7 +572,7 @@ private Process StartProcess(string executable, string? arguments, LogHandler? l
Process process;
try
{
process = Process.Start(startInfo);
process = Process.Start(startInfo)!;
}
finally
{
Expand Down

0 comments on commit 3bfa46f

Please sign in to comment.