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
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

View File

@ -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;

View File

@ -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}'");
}

View File

@ -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>
@ -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" />
@ -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>

View File

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

View File

@ -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'">

View File

@ -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);

View File

@ -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>
@ -15,7 +15,11 @@
<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>
@ -23,11 +27,11 @@
<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>
@ -37,20 +41,20 @@
<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" />
@ -58,7 +62,7 @@
</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>
@ -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>

View File

@ -540,7 +540,7 @@ namespace WinSW
/// </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,
@ -572,7 +572,7 @@ namespace WinSW
Process process;
try
{
process = Process.Start(startInfo);
process = Process.Start(startInfo)!;
}
finally
{