Stop supporting .NET Framework 2.0/4.0

pull/487/head
NextTurn 2018-11-25 00:00:00 +08:00 committed by Next Turn
parent afe25d1d82
commit 2254aa78c4
16 changed files with 15 additions and 188 deletions

View File

@ -1,7 +0,0 @@
<Project>
<PropertyGroup Condition="'$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>VNEXT</DefineConstants>
</PropertyGroup>
</Project>

View File

@ -25,11 +25,7 @@ More info about the wrapper is available in the projects GitHub repository.
</dependencies>
</metadata>
<files>
<file src="artifacts\WinSW.NET2.exe" target="lib\net20-full\WinSW.NET2.exe" />
<file src="artifacts\WinSW.NET4.exe" target="lib\net40-full\WinSW.NET4.exe" />
<file src="artifacts\WinSW.NET461.exe" target="lib\net461-full\WinSW.NET461.exe" />
<file src="examples\sample-allOptions.xml" target="lib\net20-full\WinSW.NET2.xml" />
<file src="examples\sample-allOptions.xml" target="lib\net40-full\WinSW.NET4.xml" />
<file src="examples\sample-allOptions.xml" target="lib\net461-full\WinSW.NET461.xml" />
<file src="artifacts\WinSW.NET461.exe" target="lib\net461\WinSW.NET461.exe" />
<file src="examples\sample-allOptions.xml" target="lib\net461\WinSW.NET461.xml" />
</files>
</package>

View File

@ -46,16 +46,6 @@ jobs:
versionEnvVar: BuildVersion
- script: dotnet test -c $(BuildConfiguration) --no-build src\Test\winswTests\winswTests.csproj
displayName: Test
- task: PublishBuildArtifacts@1
displayName: Publish .NET 2.0
inputs:
PathtoPublish: artifacts\WinSW.NET2.exe
ArtifactName: WinSW.NET2.exe_$(BuildConfiguration)
- task: PublishBuildArtifacts@1
displayName: Publish .NET 4.0
inputs:
PathtoPublish: artifacts\WinSW.NET4.exe
ArtifactName: WinSW.NET4.exe_$(BuildConfiguration)
- task: PublishBuildArtifacts@1
displayName: Publish .NET 4.6.1
inputs:

View File

@ -649,10 +649,8 @@ namespace winsw
FileName = current.MainModule.FileName,
#if NETCOREAPP
Arguments = "/elevated " + string.Join(' ', args),
#elif !NET20
Arguments = "/elevated " + string.Join(" ", args),
#else
Arguments = "/elevated " + string.Join(" ", args.ToArray()),
Arguments = "/elevated " + string.Join(" ", args),
#endif
WindowStyle = ProcessWindowStyle.Hidden,
};

View File

@ -6,9 +6,7 @@ using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Text.RegularExpressions;
#if VNEXT
using System.Threading.Tasks;
#endif
using log4net;
using winsw.Extensions;
using winsw.Logging;
@ -190,7 +188,6 @@ namespace winsw
HandleFileCopies();
// handle downloads
#if VNEXT
List<Download> downloads = _descriptor.Downloads;
Task[] tasks = new Task[downloads.Count];
for (int i = 0; i < downloads.Count; i++)
@ -229,32 +226,6 @@ namespace winsw
throw new AggregateException(exceptions);
}
#else
foreach (Download download in _descriptor.Downloads)
{
string downloadMessage = $"Downloading: {download.From} to {download.To}. failOnError={download.FailOnError.ToString()}";
LogEvent(downloadMessage);
Log.Info(downloadMessage);
try
{
download.Perform();
}
catch (Exception e)
{
string errorMessage = $"Failed to download {download.From} to {download.To}";
LogEvent($"{errorMessage}. {e.Message}");
Log.Error(errorMessage, e);
// TODO: move this code into the download logic
if (download.FailOnError)
{
throw new IOException(errorMessage, e);
}
// Else just keep going
}
}
#endif
string? startArguments = _descriptor.StartArguments;

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net20;net40;net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -61,19 +61,7 @@
<!-- Merge plugins and other DLLs into the executable -->
<Target Name="Merge" BeforeTargets="AfterBuild" Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net20'">
<TargetPlatform>v2</TargetPlatform>
<IdentifierSuffix>NET2</IdentifierSuffix>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
<TargetPlatform>v4</TargetPlatform>
<IdentifierSuffix>NET4</IdentifierSuffix>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<!-- v4.5+ -->
<TargetPlatform>v4.5</TargetPlatform>
<IdentifierSuffix>NET461</IdentifierSuffix>
</PropertyGroup>
@ -86,13 +74,9 @@
<OutputAssembly>"$(ArtifactsDir)WinSW.$(IdentifierSuffix).exe"</OutputAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net20' or '$(TargetFramework)' == 'net40'">
<InputAssemblies>$(InputAssemblies) "$(OutDir)ICSharpCode.SharpZipLib.dll"</InputAssemblies>
</PropertyGroup>
<PropertyGroup>
<ILMerge>$(NuGetPackageRoot)ilmerge\$(ILMergeVersion)\tools\net452\ILMerge.exe</ILMerge>
<ILMergeArgs>/targetplatform:$(TargetPlatform) /out:$(OutputAssembly) $(InputAssemblies)</ILMergeArgs>
<ILMergeArgs>/targetplatform:v4.5 /out:$(OutputAssembly) $(InputAssemblies)</ILMergeArgs>
<ILMergeCommand>"$(ILMerge)" $(ILMergeArgs)</ILMergeCommand>
</PropertyGroup>

View File

@ -1,13 +1,8 @@
using System;
using System.IO;
using System.Net;
#if !VNEXT
using System.Reflection;
#endif
using System.Text;
#if VNEXT
using System.Threading.Tasks;
#endif
using System.Xml;
using log4net;
using winsw.Util;
@ -40,33 +35,13 @@ namespace winsw
public string ShortId => $"(download from {From})";
#if NET461
static Download()
{
#if NET461
// If your app runs on .NET Framework 4.7 or later versions, but targets an earlier version
AppContext.SetSwitch("Switch.System.Net.DontEnableSystemDefaultTlsVersions", false);
#elif !VNEXT
// If your app runs on .NET Framework 4.6, but targets an earlier version
Type.GetType("System.AppContext")?.InvokeMember("SetSwitch", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new object[] { "Switch.System.Net.DontEnableSchUseStrongCrypto", false });
const SecurityProtocolType Tls12 = (SecurityProtocolType)0x00000C00;
const SecurityProtocolType Tls11 = (SecurityProtocolType)0x00000300;
// Windows 7 and Windows Server 2008 R2
if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
{
try
{
ServicePointManager.SecurityProtocol |= Tls11 | Tls12;
Logger.Info("TLS 1.1/1.2 enabled");
}
catch (NotSupportedException)
{
Logger.Info("TLS 1.1/1.2 disabled");
}
}
#endif
}
#endif
// internal
public Download(
@ -144,11 +119,7 @@ namespace winsw
/// <exception cref="WebException">
/// Download failure. FailOnError flag should be processed outside.
/// </exception>
#if VNEXT
public async Task PerformAsync()
#else
public void Perform()
#endif
{
WebRequest request = WebRequest.Create(From);
if (!string.IsNullOrEmpty(Proxy))
@ -195,11 +166,7 @@ namespace winsw
string tmpFilePath = To + ".tmp";
try
{
#if VNEXT
using (WebResponse response = await request.GetResponseAsync())
#else
using (WebResponse response = request.GetResponse())
#endif
using (Stream responseStream = response.GetResponseStream())
using (FileStream tmpStream = new FileStream(tmpFilePath, FileMode.Create))
{
@ -208,13 +175,7 @@ namespace winsw
lastModified = ((HttpWebResponse)response).LastModified;
}
#if VNEXT
await responseStream.CopyToAsync(tmpStream);
#elif NET20
CopyStream(responseStream, tmpStream);
#else
responseStream.CopyTo(tmpStream);
#endif
}
FileHelper.MoveOrReplaceFile(To + ".tmp", To);
@ -236,18 +197,6 @@ namespace winsw
}
}
}
#if NET20
private static void CopyStream(Stream source, Stream destination)
{
byte[] buffer = new byte[8192];
int read;
while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
{
destination.Write(buffer, 0, read);
}
}
#endif
}
public class CustomProxyInformation

View File

@ -1,13 +1,8 @@
using System;
using System.Diagnostics;
#if VNEXT
using System.IO.Compression;
#endif
using System.IO;
using System.Threading;
#if !VNEXT
using ICSharpCode.SharpZipLib.Zip;
#endif
using winsw.Util;
namespace winsw
@ -481,7 +476,6 @@ namespace winsw
}
}
#if VNEXT
private void ZipOneFile(string sourceFilePath, string entryName, string zipFilePath)
{
ZipArchive? zipArchive = null;
@ -503,33 +497,6 @@ namespace winsw
zipArchive?.Dispose();
}
}
#else
private void ZipOneFile(string sourceFilePath, string entryName, string zipFilePath)
{
ZipFile? zipFile = null;
try
{
zipFile = new ZipFile(File.Open(zipFilePath, FileMode.OpenOrCreate));
zipFile.BeginUpdate();
if (zipFile.FindEntry(entryName, false) < 0)
{
zipFile.Add(sourceFilePath, entryName);
}
zipFile.CommitUpdate();
}
catch (Exception e)
{
EventLogger.LogEvent($"Failed to Zip the File {sourceFilePath}. Error {e.Message}");
zipFile?.AbortUpdate();
}
finally
{
zipFile?.Close();
}
}
#endif
private double SetupRollTimer(TimeSpan autoRollAtTime)
{

View File

@ -94,26 +94,15 @@ namespace winsw.Util
string rawValue = node.GetAttribute(attributeName);
string substitutedValue = Environment.ExpandEnvironmentVariables(rawValue);
#if NET20
try
{
var value = Enum.Parse(typeof(TAttributeType), substitutedValue, true);
return (TAttributeType)value;
return (TAttributeType)Enum.Parse(typeof(TAttributeType), substitutedValue, true);
}
catch (ArgumentException ex)
{
throw new InvalidDataException("Cannot parse <" + attributeName + "> Enum value from string '" + substitutedValue +
"'. Enum type: " + typeof(TAttributeType), ex);
}
#else
if (!Enum.TryParse(substitutedValue, true, out TAttributeType result))
{
throw new InvalidDataException("Cannot parse <" + attributeName + "> Enum value from string '" + substitutedValue +
"'. Enum type: " + typeof(TAttributeType));
}
return result;
#endif
}
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net20;net40;net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -38,8 +38,4 @@
<Reference Include="System.IO.Compression" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net20' or '$(TargetFramework)' == 'net40'">
<PackageReference Include="SharpZipLib" Version="0.86.0" />
</ItemGroup>
</Project>

View File

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

View File

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

View File

@ -1,5 +1,4 @@
#if VNEXT
using System;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
@ -228,4 +227,3 @@ namespace winswTests
}
}
}
#endif

View File

@ -1,5 +1,4 @@
#if VNEXT
using System;
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Constraints;
@ -26,4 +25,3 @@ namespace winswTests.Util
}
}
}
#endif

View File

@ -1,5 +1,4 @@
#if VNEXT
using System;
using System;
namespace winswTests.Util
{
@ -9,4 +8,3 @@ namespace winswTests.Util
dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerSecond));
}
}
#endif

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net40;net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<RootNamespace>winswTests</RootNamespace>