Upgrade to .NET 5

pull/568/head
NextTurn 2020-08-19 00:00:00 +08:00 committed by Next Turn
parent dcf3013f75
commit 3bfa46f5b0
9 changed files with 32 additions and 28 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 -c $(BuildConfiguration) -f netcoreapp3.1 -r win-x64 src\WinSW\WinSW.csproj -p:Version=$(BuildVersion) dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x64 -p:Version=$(BuildVersion)
dotnet publish -c $(BuildConfiguration) -f netcoreapp3.1 -r win-x86 src\WinSW\WinSW.csproj -p:Version=$(BuildVersion) dotnet publish src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x86 -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 src\WinSW\WinSW.csproj -c $(BuildConfiguration) -f net5.0 -r win-x64 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
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-x86 -p:Version=$(BuildVersion) -p:IncludeNativeLibrariesInSingleFile=true
displayName: Build displayName: Build
- task: DotNetCoreCLI@2 - task: DotNetCoreCLI@2
displayName: Test displayName: Test

View File

@ -22,7 +22,7 @@ namespace WinSW.Configuration
public abstract string Executable { get; } 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; public virtual bool HideWindow => false;

View File

@ -187,7 +187,7 @@ namespace WinSW
} }
catch (WebException e) 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}'"); Logger.Info($"Skipped downloading unmodified resource '{this.From}'");
} }

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks> <TargetFrameworks>net461;net5.0</TargetFrameworks>
<LangVersion>preview</LangVersion> <LangVersion>preview</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -15,13 +15,13 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' == 'net5.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)' == 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<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" />
@ -31,7 +31,7 @@
<PackageReference Include="System.Threading" Version="4.3.0" /> <PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />
</ItemGroup> </ItemGroup>

View File

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

View File

@ -40,7 +40,7 @@
<Target Name="Copy" BeforeTargets="AfterBuild"> <Target Name="Copy" BeforeTargets="AfterBuild">
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp5.0'"> <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>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp5.0'"> <ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp5.0'">

View File

@ -46,7 +46,7 @@ namespace WinSW
} }
using Process current = Process.GetCurrentProcess(); using Process current = Process.GetCurrentProcess();
return current.MainModule.FileName; return current.MainModule!.FileName!;
} }
} }
@ -463,7 +463,7 @@ namespace WinSW
if (username is null) if (username is null)
{ {
Console.Write("Username: "); Console.Write("Username: ");
username = Console.ReadLine(); username = Console.ReadLine()!;
} }
if (password is null && !IsSpecialAccount(username)) if (password is null && !IsSpecialAccount(username))
@ -798,7 +798,7 @@ namespace WinSW
_ = evt.WaitOne(); _ = evt.WaitOne();
Console.CancelKeyPress -= CancelKeyPress; Console.CancelKeyPress -= CancelKeyPress;
void CancelKeyPress(object sender, ConsoleCancelEventArgs e) void CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
{ {
e.Cancel = true; e.Cancel = true;
evt.Set(); evt.Set();
@ -968,14 +968,14 @@ namespace WinSW
{ {
UseShellExecute = true, UseShellExecute = true,
Verb = "runas", Verb = "runas",
FileName = current.MainModule.FileName, FileName = current.MainModule!.FileName!,
Arguments = arguments, Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
}; };
try try
{ {
using Process elevated = Process.Start(startInfo); using Process elevated = Process.Start(startInfo)!;
elevated.WaitForExit(); elevated.WaitForExit();
Environment.Exit(elevated.ExitCode); Environment.Exit(elevated.ExitCode);

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks> <TargetFrameworks>net461;net5.0</TargetFrameworks>
<LangVersion>preview</LangVersion> <LangVersion>preview</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -15,7 +15,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)' != 'netcoreapp3.1'"> <PropertyGroup Condition="'$(TargetFramework)' == 'net5.0' AND '$(RuntimeIdentifier)' != ''">
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' != 'net5.0'">
<ILMergeVersion>3.0.40</ILMergeVersion> <ILMergeVersion>3.0.40</ILMergeVersion>
</PropertyGroup> </PropertyGroup>
@ -23,11 +27,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)' == 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.7.0" /> <PackageReference Include="System.ServiceProcess.ServiceController" Version="4.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<PackageReference Include="ilmerge" Version="$(ILMergeVersion)" /> <PackageReference Include="ilmerge" Version="$(ILMergeVersion)" />
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />
</ItemGroup> </ItemGroup>
@ -37,20 +41,20 @@
<ProjectReference Include="..\WinSW.Plugins\WinSW.Plugins.csproj" /> <ProjectReference Include="..\WinSW.Plugins\WinSW.Plugins.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' != 'net5.0'">
<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)' == 'netcoreapp3.1' and '$(PublishSingleFile)' != 'true'"> <Target Name="PublishCoreZip" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0' 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)' == 'netcoreapp3.1' and '$(PublishSingleFile)' == 'true'"> <Target Name="PublishCoreExe" AfterTargets="Publish" Condition="'$(TargetFramework)' == 'net5.0' 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" />
@ -58,7 +62,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)' != 'netcoreapp3.1'"> <Target Name="Merge" BeforeTargets="AfterBuild" Condition="'$(TargetFramework)' != 'net5.0'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'"> <PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<TargetFrameworkSuffix>NET461</TargetFrameworkSuffix> <TargetFrameworkSuffix>NET461</TargetFrameworkSuffix>
@ -90,7 +94,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)' != 'netcoreapp3.1'"> <Target Name="Trim" AfterTargets="Merge" Condition="'$(TargetFramework)' != 'net5.0'">
<Trim Path="$(ArtifactsPublishDir)WinSW.$(TargetFrameworkSuffix).exe" /> <Trim Path="$(ArtifactsPublishDir)WinSW.$(TargetFrameworkSuffix).exe" />
</Target> </Target>

View File

@ -540,7 +540,7 @@ namespace WinSW
/// </summary> /// </summary>
private Process StartProcess(string executable, string? arguments, LogHandler? logHandler = null, Action<Process>? onExited = null) 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, UseShellExecute = false,
WorkingDirectory = this.config.WorkingDirectory, WorkingDirectory = this.config.WorkingDirectory,
@ -572,7 +572,7 @@ namespace WinSW
Process process; Process process;
try try
{ {
process = Process.Start(startInfo); process = Process.Start(startInfo)!;
} }
finally finally
{ {