From 3bfa46f5b0346354560432bc6da14dc2b97cf5d4 Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Wed, 19 Aug 2020 00:00:00 +0800 Subject: [PATCH] Upgrade to .NET 5 --- eng/build.yml | 8 +++---- src/WinSW.Core/Configuration/ServiceConfig.cs | 2 +- src/WinSW.Core/Download.cs | 2 +- src/WinSW.Core/WinSW.Core.csproj | 8 +++---- src/WinSW.Plugins/WinSW.Plugins.csproj | 2 +- src/WinSW.Tests/WinSW.Tests.csproj | 2 +- src/WinSW/Program.cs | 10 ++++----- src/WinSW/WinSW.csproj | 22 +++++++++++-------- src/WinSW/WrapperService.cs | 4 ++-- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/eng/build.yml b/eng/build.yml index c2f181a..33733f4 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -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 diff --git a/src/WinSW.Core/Configuration/ServiceConfig.cs b/src/WinSW.Core/Configuration/ServiceConfig.cs index 1f2fffe..33fbfe3 100644 --- a/src/WinSW.Core/Configuration/ServiceConfig.cs +++ b/src/WinSW.Core/Configuration/ServiceConfig.cs @@ -22,7 +22,7 @@ namespace WinSW.Configuration 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; diff --git a/src/WinSW.Core/Download.cs b/src/WinSW.Core/Download.cs index 5b9810d..987531c 100644 --- a/src/WinSW.Core/Download.cs +++ b/src/WinSW.Core/Download.cs @@ -187,7 +187,7 @@ namespace WinSW } 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}'"); } diff --git a/src/WinSW.Core/WinSW.Core.csproj b/src/WinSW.Core/WinSW.Core.csproj index d47dd3d..67c7410 100644 --- a/src/WinSW.Core/WinSW.Core.csproj +++ b/src/WinSW.Core/WinSW.Core.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp3.1 + net461;net5.0 preview enable true @@ -15,13 +15,13 @@ - + - + @@ -31,7 +31,7 @@ - + diff --git a/src/WinSW.Plugins/WinSW.Plugins.csproj b/src/WinSW.Plugins/WinSW.Plugins.csproj index fe517a3..495b320 100644 --- a/src/WinSW.Plugins/WinSW.Plugins.csproj +++ b/src/WinSW.Plugins/WinSW.Plugins.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp3.1 + net461;net5.0 latest enable diff --git a/src/WinSW.Tests/WinSW.Tests.csproj b/src/WinSW.Tests/WinSW.Tests.csproj index bc0969c..07d6bd6 100644 --- a/src/WinSW.Tests/WinSW.Tests.csproj +++ b/src/WinSW.Tests/WinSW.Tests.csproj @@ -40,7 +40,7 @@ - <_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\netcoreapp3.1\WinSW.runtimeconfig*.json" /> + <_FilesToCopy Include="$(ArtifactsBinDir)WinSW\$(Configuration)\net5.0\WinSW.runtimeconfig*.json" /> diff --git a/src/WinSW/Program.cs b/src/WinSW/Program.cs index b394fe1..9611167 100644 --- a/src/WinSW/Program.cs +++ b/src/WinSW/Program.cs @@ -46,7 +46,7 @@ namespace WinSW } using Process current = Process.GetCurrentProcess(); - return current.MainModule.FileName; + return current.MainModule!.FileName!; } } @@ -463,7 +463,7 @@ namespace WinSW if (username is null) { Console.Write("Username: "); - username = Console.ReadLine(); + username = Console.ReadLine()!; } if (password is null && !IsSpecialAccount(username)) @@ -798,7 +798,7 @@ namespace WinSW _ = evt.WaitOne(); Console.CancelKeyPress -= CancelKeyPress; - void CancelKeyPress(object sender, ConsoleCancelEventArgs e) + void CancelKeyPress(object? sender, ConsoleCancelEventArgs e) { e.Cancel = true; evt.Set(); @@ -968,14 +968,14 @@ namespace WinSW { 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); diff --git a/src/WinSW/WinSW.csproj b/src/WinSW/WinSW.csproj index 28e16a6..e5dc85b 100644 --- a/src/WinSW/WinSW.csproj +++ b/src/WinSW/WinSW.csproj @@ -2,7 +2,7 @@ Exe - net461;netcoreapp3.1 + net461;net5.0 preview enable true @@ -15,7 +15,11 @@ Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees, Inc., Oleg Nenashev and other contributors - + + true + + + 3.0.40 @@ -23,11 +27,11 @@ - + - + @@ -37,20 +41,20 @@ - + false - + - + @@ -58,7 +62,7 @@ - + NET461 @@ -90,7 +94,7 @@ - + diff --git a/src/WinSW/WrapperService.cs b/src/WinSW/WrapperService.cs index ddb7b7b..932013f 100644 --- a/src/WinSW/WrapperService.cs +++ b/src/WinSW/WrapperService.cs @@ -540,7 +540,7 @@ namespace WinSW /// private Process StartProcess(string executable, string? arguments, LogHandler? logHandler = null, Action? onExited = null) { - var startInfo = new ProcessStartInfo(executable, arguments) + var startInfo = new ProcessStartInfo(executable, arguments ?? string.Empty) { UseShellExecute = false, WorkingDirectory = this.config.WorkingDirectory, @@ -572,7 +572,7 @@ namespace WinSW Process process; try { - process = Process.Start(startInfo); + process = Process.Start(startInfo)!; } finally {