Update to latest xunit, and target net472 and netstandard2.0

This commit is contained in:
Kevin Pilch 2018-12-02 17:01:12 -08:00
Родитель b7293a15f7
Коммит 41c9282023
6 изменённых файлов: 116 добавлений и 6 удалений

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>Xunit.Runner.Data</RootNamespace>
<TargetFramework>net452</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

Просмотреть файл

@ -0,0 +1,110 @@
#if NETFRAMEWORK
// Taken from https://github.com/xunit/xunit/blob/master/src/common/AssemblyResolution/AssemblyHelper_Desktop.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Xunit
{
/// <summary>
/// This class provides assistance with assembly resolution for missing assemblies.
/// </summary>
class AssemblyHelper : LongLivedMarshalByRefObject, IDisposable
{
static readonly string[] Extensions = { ".dll", ".exe" };
readonly string directory;
readonly IMessageSink internalDiagnosticsMessageSink;
readonly Dictionary<string, Assembly> lookupCache = new Dictionary<string, Assembly>();
/// <summary>
/// Constructs an instance using the given <paramref name="directory"/> for resolution.
/// </summary>
/// <param name="directory">The directory to use for resolving assemblies.</param>
public AssemblyHelper(string directory) : this(directory, null) { }
/// <summary>
/// Constructs an instance using the given <paramref name="directory"/> for resolution.
/// </summary>
/// <param name="directory">The directory to use for resolving assemblies.</param>
/// <param name="internalDiagnosticsMessageSink">The message sink to send internal diagnostics messages to</param>
public AssemblyHelper(string directory, IMessageSink internalDiagnosticsMessageSink)
{
this.directory = directory;
this.internalDiagnosticsMessageSink = internalDiagnosticsMessageSink;
AppDomain.CurrentDomain.AssemblyResolve += Resolve;
}
/// <inheritdoc/>
public void Dispose()
=> AppDomain.CurrentDomain.AssemblyResolve -= Resolve;
Assembly LoadAssembly(AssemblyName assemblyName)
{
if (lookupCache.TryGetValue(assemblyName.Name, out var result))
return result;
var path = Path.Combine(directory, assemblyName.Name);
result = ResolveAndLoadAssembly(path, out var resolvedAssemblyPath);
if (internalDiagnosticsMessageSink != null)
{
if (result == null)
internalDiagnosticsMessageSink.OnMessage(new DiagnosticMessage($"[AssemblyHelper_Desktop.LoadAssembly] Resolution for '{assemblyName.Name}' failed, passed down to next resolver"));
else
internalDiagnosticsMessageSink.OnMessage(new DiagnosticMessage($"[AssemblyHelper_Desktop.LoadAssembly] Resolved '{assemblyName.Name}' to '{resolvedAssemblyPath}'"));
}
lookupCache[assemblyName.Name] = result;
return result;
}
Assembly Resolve(object sender, ResolveEventArgs args)
=> LoadAssembly(new AssemblyName(args.Name));
Assembly ResolveAndLoadAssembly(string pathWithoutExtension, out string resolvedAssemblyPath)
{
foreach (var extension in Extensions)
{
resolvedAssemblyPath = pathWithoutExtension + extension;
try
{
if (File.Exists(resolvedAssemblyPath))
return Assembly.LoadFrom(resolvedAssemblyPath);
}
catch { }
}
resolvedAssemblyPath = null;
return null;
}
/// <summary>
/// Subscribes to the appropriate assembly resolution event, to provide automatic assembly resolution for
/// an assembly and any of its dependencies. Depending on the target platform, this may include the use
/// of the .deps.json file generated during the build process.
/// </summary>
/// <returns>An object which, when disposed, un-subscribes.</returns>
public static IDisposable SubscribeResolveForAssembly(string assemblyFileName, IMessageSink internalDiagnosticsMessageSink = null)
=> new AssemblyHelper(Path.GetDirectoryName(Path.GetFullPath(assemblyFileName)), internalDiagnosticsMessageSink);
/// <summary>
/// Subscribes to the appropriate assembly resolution event, to provide automatic assembly resolution for
/// an assembly and any of its dependencies. Depending on the target platform, this may include the use
/// of the .deps.json file generated during the build process.
/// </summary>
/// <returns>An object which, when disposed, un-subscribes.</returns>
public static IDisposable SubscribeResolveForAssembly(Type typeInAssembly, IMessageSink internalDiagnosticsMessageSink = null)
=> new AssemblyHelper(Path.GetDirectoryName(typeInAssembly.Assembly.Location), internalDiagnosticsMessageSink);
}
}
#endif

Просмотреть файл

@ -9,7 +9,7 @@ namespace Xunit.Runner.Worker
protected static void Go(string assemblyFileName, Stream stream, AppDomainSupport appDomainSupport,
Action<XunitFrontController, TestAssemblyConfiguration, ClientWriter> action)
{
using (AssemblyHelper.SubscribeResolve())
using (AssemblyHelper.SubscribeResolveForAssembly(assemblyFileName))
using (var xunit = new XunitFrontController(appDomainSupport, assemblyFileName, shadowCopy: false))
using (var writer = new ClientWriter(stream))
{

Просмотреть файл

@ -3,11 +3,11 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Xunit.Runner.Worker</RootNamespace>
<TargetFramework>net452</TargetFramework>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit.runner.utility" Version="2.1.0" />
<PackageReference Include="xunit.runner.utility" Version="2.4.1" />
<ProjectReference Include="..\xunit.runner.data\xunit.runner.data.csproj" />
</ItemGroup>

Просмотреть файл

@ -9,6 +9,7 @@
<Authors>Pilchie</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackAsTool>true</PackAsTool>
<AssetTargetFallback>net472</AssetTargetFallback>
<Description>XUnit Gui written in WPF</Description>
<PackageProjectUrl>https://github.com/Pilchie/xunit.runner.wpf</PackageProjectUrl>
<RepositoryUrl>https://github.com/Pilchie/xunit.runner.wpf</RepositoryUrl>
@ -27,7 +28,6 @@
<PackageReference Include="System.Collections.Immutable" Version="1.4.0-preview1-25305-02" />
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
<PackageReference Include="WindowsAPICodePack" Version="1.1.0" />
<PackageReference Include="xunit.runner.utility" Version="2.4.1" />
</ItemGroup>
<ItemGroup>