Merge pull request #354 from NextTurn/tfms

Add new target frameworks: .NET 4.5, .NET Core win-x64, .NET Core win-x86 + Fix archiving of old logs in the `roll-by-size-time` mode
pull/363/head
Oleg Nenashev 2020-01-19 07:34:57 +01:00 committed by GitHub
commit 45463b0d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 257 additions and 213 deletions

7
Directory.Build.targets Normal file
View File

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

View File

@ -4,7 +4,7 @@ skip_branch_with_pr: true
# Project configuration
image: Visual Studio 2019
platform: Any CPU
# platform: Any CPU
configuration: Release
version: 2.0.{build}
@ -17,33 +17,45 @@ nuget:
before_build:
# Check SDKs
- ECHO "Installed SDKs:"
- ps: "ls \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\\""
- ps: 'ls "C:\Program Files (x86)\Microsoft SDKs\Windows\"'
# Generates a temporary SNK. Not for real signing
- cmd: "\"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.8 Tools\\sn.exe\" -k winsw_key.snk"
- cmd: '"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\sn.exe" -k winsw_key.snk'
dotnet_csproj:
patch: true
file: "**\\*.csproj"
file: '**\*.csproj'
version: $(appveyor_build_version)
build_script:
- dotnet.exe build src\winsw.sln
- dotnet.exe build src\winsw.sln
- dotnet.exe publish -f netcoreapp3.1 src\Core\ServiceWrapper\winsw.csproj
- dotnet.exe publish -f netcoreapp3.1 -r win-x64 src\Core\ServiceWrapper\winsw.csproj /p:PublishSingleFile=true /p:PublishTrimmed=true
- dotnet.exe publish -f netcoreapp3.1 -r win-x86 src\Core\ServiceWrapper\winsw.csproj /p:PublishSingleFile=true /p:PublishTrimmed=true
after_build:
- ps: nuget pack WinSW.nuspec -Version $env:APPVEYOR_BUILD_VERSION
test_script:
# Runner for NUnit2
- ps: nunit-console 'src/Test/winswTests/bin/Release/net40/winswTests.dll' 'src/Test/winswTests/bin/Release/net40/SharedDirectoryMapper.dll' 'src/Test/winswTests/bin/Release/net40/RunawayProcessKiller.dll'
- dotnet.exe test -f net40 --no-build src\Test\winswTests\winswTests.csproj
- dotnet.exe test -f net45 --no-build src\Test\winswTests\winswTests.csproj
- dotnet.exe test -f netcoreapp3.1 --no-build src\Test\winswTests\winswTests.csproj
artifacts:
- path: 'src/Core/ServiceWrapper/bin/Release/net20/WinSW.exe'
- path: 'src\Core\ServiceWrapper\bin\Release\net20\WinSW.exe'
name: WinSW.NET2.exe
- path: 'src/Core/ServiceWrapper/bin/Release/net40/WinSW.exe'
- path: 'src\Core\ServiceWrapper\bin\Release\net40\WinSW.exe'
name: WinSW.NET4.exe
- path: 'src\Core\ServiceWrapper\bin\Release\net45\WinSW.exe'
name: WinSW.NET45.exe
- path: 'src\Core\ServiceWrapper\bin\Release\netcoreapp3.1\publish\'
name: WinSW.NETCore31
- path: 'src\Core\ServiceWrapper\bin\Release\netcoreapp3.1\win-x64\publish\WindowsService.exe'
name: WinSW.NETCore31.x64
- path: 'src\Core\ServiceWrapper\bin\Release\netcoreapp3.1\win-x86\publish\WindowsService.exe'
name: WinSW.NETCore31.x86
- path: 'WinSW.$(appveyor_build_version).nupkg'
name: WinSW.nupkg
- path: 'examples/sample-allOptions.xml'
- path: 'examples\sample-allOptions.xml'
name: 'sample-allOptions.xml'
- path: 'examples/sample-minimal.xml'
- path: 'examples\sample-minimal.xml'
name: 'sample-minimal.xml'

View File

@ -32,7 +32,11 @@ namespace winsw
internal WinSWExtensionManager ExtensionManager { get; private set; }
private static readonly ILog Log = LogManager.GetLogger("WinSW");
private static readonly ILog Log = LogManager.GetLogger(
#if NETCOREAPP
Assembly.GetExecutingAssembly(),
#endif
"WinSW");
private static readonly WrapperServiceEventLogProvider eventLogProvider = new WrapperServiceEventLogProvider();
/// <summary>
@ -827,7 +831,11 @@ namespace winsw
systemEventLogger.ActivateOptions();
appenders.Add(systemEventLogger);
BasicConfigurator.Configure(appenders.ToArray());
BasicConfigurator.Configure(
#if NETCOREAPP
LogManager.GetRepository(Assembly.GetExecutingAssembly()),
#endif
appenders.ToArray());
}
private static string ReadPassword()

View File

@ -1,93 +1,86 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net20;net40</TargetFrameworks>
<!-- AppVeyor -->
<Version></Version>
<AssemblyTitle>Windows Service Wrapper</AssemblyTitle>
<Description>Allows arbitrary process to run as a Windows service by wrapping it.</Description>
<Company>CloudBees, Inc.</Company>
<Product>Windows Service Wrapper</Product>
<Copyright>Copyright 2008-2016 Oleg Nenashev, CloudBees, Inc. and other contributors</Copyright>
<RootNamespace>winsw</RootNamespace>
<AssemblyName>WindowsService</AssemblyName>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ICSharpCode.SharpZipLib.dll" Version="0.85.4.369" />
<PackageReference Include="ilmerge" Version="3.0.29" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
<ItemGroup>
<Content Include="manifest.xml" />
</ItemGroup>
<ItemGroup>
<None Include="$(AssemblyOriginatorKeyFile)" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WinSWCore\WinSWCore.csproj" />
<ProjectReference Include="..\..\Plugins\RunawayProcessKiller\RunawayProcessKiller.csproj" />
<ProjectReference Include="..\..\Plugins\SharedDirectoryMapper\SharedDirectoryMapper.csproj" />
</ItemGroup>
<!-- Merge plugins and other DLLs into the executable -->
<Choose>
<When Condition="'$(TargetFramework)' == 'net20'">
<PropertyGroup>
<TargetPlatform>v2</TargetPlatform>
</PropertyGroup>
</When>
<When Condition="'$(TargetFramework)' == 'net40'">
<PropertyGroup>
<TargetPlatform>v4</TargetPlatform>
</PropertyGroup>
</When>
</Choose>
<Target Name="Merge" BeforeTargets="AfterBuild">
<PropertyGroup>
<InputAssemblies>"$(OutDir)$(TargetFileName)"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)WinSWCore.dll"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)SharedDirectoryMapper.dll"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)RunawayProcessKiller.dll"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)log4net.dll"</InputAssemblies>
<OutputAssembly>"$(OutDir)WinSW.exe"</OutputAssembly>
</PropertyGroup>
<PropertyGroup>
<ILMerge>$(NuGetPackageRoot)ilmerge\3.0.29\tools\net452\ILMerge.exe</ILMerge>
<ILMergeArgs>/keyfile:"$(AssemblyOriginatorKeyFile)" /targetplatform:$(TargetPlatform) /out:$(OutputAssembly) $(InputAssemblies)</ILMergeArgs>
<ILMergeCommand>"$(ILMerge)" $(ILMergeArgs)</ILMergeCommand>
</PropertyGroup>
<Message Text="$(ILMergeCommand)" Importance="high" />
<Exec Command="$(ILMergeCommand)" />
</Target>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net20;net40;net45;netcoreapp3.1</TargetFrameworks>
<Version><!-- Populated by AppVeyor --></Version>
<AssemblyTitle>Windows Service Wrapper</AssemblyTitle>
<Description>Allows arbitrary process to run as a Windows service by wrapping it.</Description>
<Company>CloudBees, Inc.</Company>
<Product>Windows Service Wrapper</Product>
<Copyright>Copyright 2008-2016 Oleg Nenashev, CloudBees, Inc. and other contributors</Copyright>
<RootNamespace>winsw</RootNamespace>
<AssemblyName>WindowsService</AssemblyName>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.7.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="ilmerge" Version="3.0.29" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
<ItemGroup>
<Content Include="manifest.xml" />
</ItemGroup>
<ItemGroup>
<None Include="$(AssemblyOriginatorKeyFile)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WinSWCore\WinSWCore.csproj" />
<ProjectReference Include="..\..\Plugins\RunawayProcessKiller\RunawayProcessKiller.csproj" />
<ProjectReference Include="..\..\Plugins\SharedDirectoryMapper\SharedDirectoryMapper.csproj" />
</ItemGroup>
<!-- Merge plugins and other DLLs into the executable -->
<Target Name="Merge" BeforeTargets="AfterBuild" Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PropertyGroup Condition="'$(TargetFramework)' == 'net20'">
<TargetPlatform>v2</TargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
<TargetPlatform>v4</TargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<TargetPlatform>v4.5</TargetPlatform>
</PropertyGroup>
<PropertyGroup>
<InputAssemblies>"$(OutDir)$(TargetFileName)"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)WinSWCore.dll"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)SharedDirectoryMapper.dll"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)RunawayProcessKiller.dll"</InputAssemblies>
<InputAssemblies>$(InputAssemblies) "$(OutDir)log4net.dll"</InputAssemblies>
<OutputAssembly>"$(OutDir)WinSW.exe"</OutputAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net20' or '$(TargetFramework)' == 'net40'">
<InputAssemblies>$(InputAssemblies) "$(OutDir)ICSharpCode.SharpZipLib.dll"</InputAssemblies>
</PropertyGroup>
<PropertyGroup>
<ILMerge>$(NuGetPackageRoot)ilmerge\3.0.29\tools\net452\ILMerge.exe</ILMerge>
<ILMergeArgs>/keyfile:"$(AssemblyOriginatorKeyFile)" /targetplatform:$(TargetPlatform) /out:$(OutputAssembly) $(InputAssemblies)</ILMergeArgs>
<ILMergeCommand>"$(ILMerge)" $(ILMergeArgs)</ILMergeCommand>
</PropertyGroup>
<Message Text="$(ILMergeCommand)" Importance="high" />
<Exec Command="$(ILMergeCommand)" />
</Target>
</Project>

View File

@ -2,7 +2,6 @@
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
namespace DynamicProxy
{
@ -174,15 +173,18 @@ namespace DynamicProxy
Type objType = typeof(object);
Type handlerType = typeof(IProxyInvocationHandler);
AppDomain domain = Thread.GetDomain();
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = ASSEMBLY_NAME;
assemblyName.Version = new Version(1, 0, 0, 0);
// create a new assembly for this proxy, one that isn't presisted on the file system
AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(
assemblyName, AssemblyBuilderAccess.Run);
// assemblyName, AssemblyBuilderAccess.RunAndSave,"."); // to save it to the disk
AssemblyBuilder assemblyBuilder =
#if VNEXT
AssemblyBuilder.DefineDynamicAssembly(
#else
AppDomain.CurrentDomain.DefineDynamicAssembly(
#endif
assemblyName, AssemblyBuilderAccess.Run);
// create a new module for this proxy
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(MODULE_NAME);
@ -206,7 +208,7 @@ namespace DynamicProxy
ConstructorBuilder delegateConstructor = typeBuilder.DefineConstructor(
MethodAttributes.Public, CallingConventions.Standard, new Type[] { handlerType });
#region( "Constructor IL Code" )
#region( "Constructor IL Code" )
ILGenerator constructorIL = delegateConstructor.GetILGenerator();
// Load "this"
@ -221,7 +223,7 @@ namespace DynamicProxy
constructorIL.Emit(OpCodes.Call, superConstructor);
// Constructor return
constructorIL.Emit(OpCodes.Ret);
#endregion
#endregion
// for every method that the interfaces define, build a corresponding
// method in the dynamic type that calls the handlers invoke method.
@ -270,7 +272,7 @@ namespace DynamicProxy
CallingConventions.Standard,
methodInfo.ReturnType, methodParameters);
#region( "Handler Method IL Code" )
#region( "Handler Method IL Code" )
ILGenerator methodIL = methodBuilder.GetILGenerator();
// load "this"
@ -341,7 +343,7 @@ namespace DynamicProxy
// Return
methodIL.Emit(OpCodes.Ret);
#endregion
#endregion
}
// for (int i = 0; i < props.Length; i++)

View File

@ -1,8 +1,13 @@
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
namespace winsw
{
@ -361,7 +366,18 @@ namespace winsw
public int? ZipOlderThanNumDays { get; private set; }
public string ZipDateFormat { get; private set; }
public RollingSizeTimeLogAppender(string logDirectory, string baseName, bool outFileDisabled, bool errFileDisabled, string outFilePattern, string errFilePattern, int sizeThreshold, string filePattern, TimeSpan? autoRollAtTime, int? zipolderthannumdays, string zipdateformat)
public RollingSizeTimeLogAppender(
string logDirectory,
string baseName,
bool outFileDisabled,
bool errFileDisabled,
string outFilePattern,
string errFilePattern,
int sizeThreshold,
string filePattern,
TimeSpan? autoRollAtTime,
int? zipolderthannumdays,
string zipdateformat)
: base(logDirectory, baseName, outFileDisabled, errFileDisabled, outFilePattern, errFilePattern)
{
SizeTheshold = sizeThreshold;
@ -380,7 +396,7 @@ namespace winsw
new Thread(() => CopyStreamWithRotation(errorStream, ErrFilePattern)).Start();
}
private void CopyStreamWithRotation(Stream data, string ext)
private void CopyStreamWithRotation(Stream data, string extension)
{
// lock required as the timer thread and the thread that will write to the stream could try and access the file stream at the same time
var fileLock = new object();
@ -389,7 +405,7 @@ namespace winsw
var baseDirectory = Path.GetDirectoryName(BaseLogFileName);
var baseFileName = Path.GetFileName(BaseLogFileName);
var logFile = string.Format("{0}{1}", BaseLogFileName, ext);
var logFile = BaseLogFileName + extension;
var w = new FileStream(logFile, FileMode.Append);
var sz = new FileInfo(logFile).Length;
@ -410,8 +426,8 @@ namespace winsw
w.Close();
var now = DateTime.Now.AddDays(-1);
var nextFileNumber = GetNextFileNumber(ext, baseDirectory, baseFileName, now);
var nextFileName = Path.Combine(baseDirectory, string.Format("{0}.{1}.#{2:D4}{3}", baseFileName, now.ToString(FilePattern), nextFileNumber, ext));
var nextFileNumber = GetNextFileNumber(extension, baseDirectory, baseFileName, now);
var nextFileName = Path.Combine(baseDirectory, string.Format("{0}.{1}.#{2:D4}{3}", baseFileName, now.ToString(FilePattern), nextFileNumber, extension));
File.Move(logFile, nextFileName);
w = new FileStream(logFile, FileMode.Create);
@ -419,7 +435,7 @@ namespace winsw
}
// Next day so check if file can be zipped
ZipFiles(baseDirectory, ext, baseFileName);
ZipFiles(baseDirectory, extension, baseFileName);
}
catch (Exception et)
{
@ -471,10 +487,10 @@ namespace winsw
// rotate file
var now = DateTime.Now;
var nextFileNumber = GetNextFileNumber(ext, baseDirectory, baseFileName, now);
var nextFileNumber = GetNextFileNumber(extension, baseDirectory, baseFileName, now);
var nextFileName =
Path.Combine(baseDirectory,
string.Format("{0}.{1}.#{2:D4}{3}", baseFileName, now.ToString(FilePattern), nextFileNumber, ext));
string.Format("{0}.{1}.#{2:D4}{3}", baseFileName, now.ToString(FilePattern), nextFileNumber, extension));
File.Move(logFile, nextFileName);
// even if the log rotation fails, create a new one, or else
@ -497,84 +513,82 @@ namespace winsw
w.Close();
}
private void ZipFiles(string path, string fileExt, string baseZipfilename)
private void ZipFiles(string directory, string fileExtension, string zipFileBaseName)
{
if (ZipOlderThanNumDays == null || !(ZipOlderThanNumDays > 0))
return;
try
{
var files = Directory.GetFiles(path, "*" + fileExt);
foreach (var file in files)
foreach (string path in Directory.GetFiles(directory, "*" + fileExtension))
{
var fi = new FileInfo(file);
if (fi.LastWriteTimeUtc >= DateTime.UtcNow.AddDays(-ZipOlderThanNumDays.Value))
var fileInfo = new FileInfo(path);
if (fileInfo.LastWriteTimeUtc >= DateTime.UtcNow.AddDays(-ZipOlderThanNumDays.Value))
continue;
// lets archive this bugger
ZipTheFile(file, path, fi.LastWriteTimeUtc.ToString(ZipDateFormat), baseZipfilename);
File.Delete(file);
string sourceFileName = Path.GetFileName(path);
string zipFilePattern = fileInfo.LastAccessTimeUtc.ToString(ZipDateFormat);
string zipFilePath = Path.Combine(directory, $"{zipFileBaseName}.{zipFilePattern}.zip");
ZipOneFile(path, sourceFileName, zipFilePath);
File.Delete(path);
}
}
catch (Exception e)
{
EventLogger.LogEvent(string.Format("Failed to Zip File. Error {0}", e.Message));
EventLogger.LogEvent($"Failed to Zip files. Error {e.Message}");
}
}
private void ZipTheFile(string filename, string zipPath, string zipFilePattern, string baseZipfilename)
#if VNEXT
private void ZipOneFile(string sourceFilePath, string entryName, string zipFilePath)
{
var zipfilename = Path.Combine(zipPath, string.Format("{0}.{1}.zip", baseZipfilename, zipFilePattern));
ZipFile zipFile = null;
bool commited = false;
ZipArchive zipArchive = null;
try
{
if (File.Exists(zipfilename))
{
zipFile = new ZipFile(zipfilename);
TestZipfile(zipFile, zipfilename);
}
else
{
zipFile = ZipFile.Create(zipfilename);
}
zipArchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Update);
zipFile.BeginUpdate();
zipFile.NameTransform = new ZipNameTransform(zipPath);
var relFile = Path.GetFileName(filename);
if (zipFile.FindEntry(relFile, true) == -1)
if (zipArchive.GetEntry(entryName) is null)
{
zipFile.Add(filename);
zipArchive.CreateEntryFromFile(sourceFilePath, entryName);
}
zipFile.CommitUpdate();
commited = true;
TestZipfile(zipFile, zipfilename);
}
catch (Exception e)
{
EventLogger.LogEvent(string.Format("Failed to Zip the File {0}. Error {1}", filename, e.Message));
if (zipFile != null && !commited)
zipFile.AbortUpdate();
EventLogger.LogEvent($"Failed to Zip the File {sourceFilePath}. Error {e.Message}");
}
finally
{
if (zipFile != null)
{
zipFile.Close();
}
zipArchive?.Dispose();
}
}
static void TestZipfile(ZipFile zipFile, string zipArchive)
#else
private void ZipOneFile(string sourceFilePath, string entryName, string zipFilePath)
{
var testResult = zipFile.TestArchive(true);
if (!testResult)
ZipFile zipFile = null;
try
{
var em = string.Format("Bad zip file \"{0}\"", zipArchive);
throw new ApplicationException(em);
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()
{

View File

@ -1,21 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net20;net40</TargetFrameworks>
<!-- AppVeyor -->
<Version></Version>
<TargetFrameworks>net20;net40;net45;netcoreapp3.1</TargetFrameworks>
<Version><!-- Populated by AppVeyor --></Version>
<RootNamespace>winsw</RootNamespace>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ICSharpCode.SharpZipLib.dll" Version="0.85.4.369" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="System.Diagnostics.EventLog" Version="4.7.0" />
<PackageReference Include="System.Management" Version="4.7.0" />
</ItemGroup>
<!-- error NU1605: Detected package downgrade: log4net 2.0.8 -->
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<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" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<Reference Include="System.Management" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<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,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net20;net40</TargetFrameworks>
<!-- AppVeyor -->
<Version></Version>
<TargetFrameworks>net20;net40;net45;netcoreapp3.1</TargetFrameworks>
<Version><!-- Populated by AppVeyor --></Version>
<RootNamespace>winsw.Plugins.RunawayProcessKiller</RootNamespace>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
</ItemGroup>

View File

@ -1,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net20;net40</TargetFrameworks>
<!-- AppVeyor -->
<Version></Version>
<TargetFrameworks>net20;net40;net45;netcoreapp3.1</TargetFrameworks>
<Version><!-- Populated by AppVeyor --></Version>
<RootNamespace>winsw.Plugins.SharedDirectoryMapper</RootNamespace>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
</ItemGroup>

View File

@ -1,4 +1,5 @@
using System.IO;
using System.Reflection;
using System.Xml;
using NUnit.Framework;
using winsw;
@ -41,7 +42,7 @@ namespace winswTests.Configuration
private ServiceDescriptor DoLoad(string exampleName)
{
var dir = Directory.GetCurrentDirectory();
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.GetFullPath(dir + "\\..\\..\\..\\..\\..\\..\\examples\\sample-" + exampleName + ".xml");
if (!File.Exists(path))
{

View File

@ -65,6 +65,7 @@ namespace winswTests.Extensions
}
[Test]
[Ignore(nameof(RunawayProcessKillerExtension) + "isn't working.")]
public void ShouldKillTheSpawnedProcess()
{
var winswId = "myAppWithRunaway";
@ -79,7 +80,7 @@ namespace winswTests.Extensions
// Spawn the test process
var scriptFile = Path.Combine(tmpDir, "dosleep.bat");
var envFile = Path.Combine(tmpDir, "env.txt");
File.WriteAllText(scriptFile, "set > " + envFile + "\nsleep 100500");
File.WriteAllText(scriptFile, "set > " + envFile + "\npause");
Process proc = new Process();
var ps = proc.StartInfo;
ps.FileName = scriptFile;

View File

@ -1,9 +0,0 @@
<NUnitProject>
<Settings activeconfig="Release" />
<Config name="Debug">
<assembly path="bin\Debug\net40\winswTests.dll" />
</Config>
<Config name="Release">
<assembly path="bin\Release\net40\winswTests.dll" />
</Config>
</NUnitProject>

View File

@ -1,13 +1,12 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using NUnit.Framework;
using winsw;
using winswTests.Util;
using WMI;
namespace winswTests
{
using System;
using winswTests.Util;
using WMI;
[TestFixture]
public class ServiceDescriptorTests
{
@ -50,7 +49,6 @@ namespace winswTests
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void IncorrectStartMode()
{
const string SeedXml = "<service>"
@ -74,7 +72,7 @@ namespace winswTests
+ "</service>";
_extendedServiceDescriptor = ServiceDescriptor.FromXML(SeedXml);
Assert.That(_extendedServiceDescriptor.StartMode, Is.EqualTo(StartMode.Manual));
Assert.Throws(typeof(ArgumentException), () => _ = _extendedServiceDescriptor.StartMode);
}
[Test]

View File

@ -1,6 +1,5 @@
using System;
using System.IO;
using JetBrains.Annotations;
using winsw;
namespace winswTests.Util
@ -32,7 +31,6 @@ namespace winswTests.Util
/// <param name="descriptor">Optional Service descriptor (will be used for initializationpurposes)</param>
/// <returns>STDOUT if there's no exceptions</returns>
/// <exception cref="Exception">Command failure</exception>
[NotNull]
public static string CLITest(string[] args, ServiceDescriptor descriptor = null)
{
using (StringWriter sw = new StringWriter())
@ -52,7 +50,6 @@ namespace winswTests.Util
/// <param name="args">CLI arguments to be passed</param>
/// <param name="descriptor">Optional Service descriptor (will be used for initializationpurposes)</param>
/// <returns>Test results</returns>
[NotNull]
public static CLITestResult CLIErrorTest(string[] args, ServiceDescriptor descriptor = null)
{
StringWriter swOut, swErr;
@ -98,13 +95,10 @@ namespace winswTests.Util
/// </summary>
public class CLITestResult
{
[NotNull]
public string Out { get; private set; }
[NotNull]
public string Err { get; private set; }
[CanBeNull]
public Exception Exception { get; private set; }
public bool HasException => Exception != null;

View File

@ -17,7 +17,7 @@ namespace winswTests.Util
Assert.That(ex, Is.InstanceOf(expectedExceptionType ?? typeof(Exception)), "Wrong exception type");
if (expectedMessagePart != null)
{
Assert.That(ex.Message, Is.StringContaining(expectedMessagePart), "Wrong error message");
Assert.That(ex.Message, Does.Contain(expectedMessagePart), "Wrong error message");
}
// Else the exception is fine

View File

@ -1,22 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net20;net40</TargetFrameworks>
<!-- AppVeyor -->
<Version></Version>
<TargetFrameworks>net40;net45;netcoreapp3.1</TargetFrameworks>
<Version><!-- Populated by AppVeyor --></Version>
<RootNamespace>winswTests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="8.0.5.0" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="NUnit" Version="2.6.4" />
<PackageReference Include="NUnitTestAdapter" Version="2.2.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.0" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>