Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void CanParseInputLine(string line, string name, string packageVer
[TestCase("Microsoft.NETCore.App", "8.0.0", "8.0.22")]
[TestCase("Microsoft.NETCore.App", "8.0.0.0", "8.0.22")]
[TestCase("Microsoft.NETCore.App", "8.0.0.100", "8.0.22")]
[TestCase("Microsoft.NETCore.App", "8.0.100", "9.0.11")]
[TestCase("Microsoft.NETCore.App", "8.0.100", "8.0.22")]
[TestCase("Microsoft.AspNetCore.App", "5.0.0", "8.0.22")] // Rather than 8.0.2
[TestCase("Microsoft.AspNetCore.App", "7.0.0", "8.0.22")] // Rather than 8.0.2
[TestCase("Microsoft.AspNetCore.App", "8.0.0", "8.0.22")] // Rather than 8.0.2
Expand Down
3 changes: 2 additions & 1 deletion src/NUnitEngine/nunit.engine.core/DotNetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ internal static bool FindBestRuntime(Version targetVersion, IEnumerable<RuntimeI

foreach (var candidate in availableRuntimes)
{
if (candidate.Version >= targetVersion)
if (candidate.Version.Major > targetVersion.Major ||
candidate.Version.Major == targetVersion.Major && candidate.Version.Minor >= candidate.Version.Minor)
if (bestRuntime is null || candidate.Version.Major == bestRuntime.Version.Major)
bestRuntime = candidate;
}
Expand Down
15 changes: 10 additions & 5 deletions src/NUnitEngine/nunit.engine.core/Drivers/NUnitNetCore31Driver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

//#define USE_DEFAULT_ASSEMBLY_LOAD_CONTEXT

#if NETCOREAPP3_1_OR_GREATER
using System;
using System.Linq;
Expand Down Expand Up @@ -66,11 +68,19 @@ public string Load(string assemblyPath, IDictionary<string, object> settings)
_testAssembly = AssemblyHelper.FindLoadedAssemblyByPath(assemblyPath);

if (_testAssembly != null)
{
_assemblyLoadContext = AssemblyLoadContext.GetLoadContext(_testAssembly);
log.Debug($" Already loaded in context {_assemblyLoadContext}");
}
else
{
#if USE_DEFAULT_ASSEMBLY_LOAD_CONTEXT
_assemblyLoadContext = AssemblyLoadContext.Default;
#else
_assemblyLoadContext = new AssemblyLoadContext(Path.GetFileNameWithoutExtension(assemblyPath));
#endif
_testAssembly = _assemblyLoadContext.LoadFromAssemblyPath(assemblyPath);
log.Debug($" Loaded into new context {_assemblyLoadContext}");
}

_testAssemblyResolver = new TestAssemblyResolver(_assemblyLoadContext, assemblyPath);
Expand Down Expand Up @@ -115,11 +125,6 @@ public string Load(string assemblyPath, IDictionary<string, object> settings)
return ExecuteMethod(LOAD_METHOD) as string;
}

private Assembly _assemblyLoadContext_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
{
throw new NotImplementedException();
}

/// <summary>
/// Counts the number of test cases for the loaded test assembly
/// </summary>
Expand Down
10 changes: 1 addition & 9 deletions src/NUnitEngine/nunit.engine.core/Internal/AssemblyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -86,14 +87,5 @@ public static Assembly FindLoadedAssemblyByPath(string assemblyPath)
!string.IsNullOrEmpty(a.Location) &&
StringComparer.OrdinalIgnoreCase.Equals(Path.GetFullPath(a.Location), full));
}

public static Assembly FindLoadedAssemblyByName(AssemblyName assemblyName)
{
return AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a =>
!a.IsDynamic &&
!string.IsNullOrEmpty(a.Location) &&
a.GetName() == assemblyName);
}
}
}
30 changes: 12 additions & 18 deletions src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.DependencyModel.Resolution;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -52,7 +53,7 @@ private void InitializeResolutionStrategies(AssemblyLoadContext loadContext, str
foreach (var reference in assemblyDef.MainModule.GetTypeReferences())
{
string fn = reference.FullName;
if (fn.StartsWith("System.Windows.") || fn.StartsWith("PresentationFramework"))
if (fn.StartsWith("System.Windows.") || fn.StartsWith("PresentationFramework") || fn == "WindowsBase")
tryWindowsDesktopFirst = true;
if (fn.StartsWith("Microsoft.AspNetCore."))
tryAspNetCoreFirst = true;
Expand Down Expand Up @@ -81,25 +82,18 @@ public void Dispose()
_loadContext.Resolving -= OnResolving;
}

//public Assembly Resolve(AssemblyLoadContext context, AssemblyName assemblyName)
//{
// return OnResolving(context, assemblyName);
//}

private Assembly OnResolving(AssemblyLoadContext loadContext, AssemblyName assemblyName)
{
if (loadContext == null) throw new ArgumentNullException("context");

//var runtimeResolverPath = _assemblyDependencyResolver.ResolveAssemblyToPath(assemblyName);
//if (!string.IsNullOrEmpty(runtimeResolverPath) && File.Exists(runtimeResolverPath))
//{
// var loadedAssembly = _loadContext.LoadFromAssemblyPath(runtimeResolverPath);
// if (loadedAssembly != null)
// {
// log.Info($"Assembly {assemblyName} ({loadedAssembly}) is loaded using the deps.json info");
// return loadedAssembly;
// }
//}
var runtimeResolverPath = _assemblyDependencyResolver.ResolveAssemblyToPath(assemblyName);
if (!string.IsNullOrEmpty(runtimeResolverPath) && File.Exists(runtimeResolverPath))
{
var loadedAssembly = _loadContext.LoadFromAssemblyPath(runtimeResolverPath);
if (loadedAssembly != null)
{
log.Info($"Assembly {assemblyName} ({loadedAssembly}) is loaded using the deps.json info");
return loadedAssembly;
}
}

foreach (var strategy in ResolutionStrategies)
if (strategy.TryToResolve(loadContext, assemblyName, out Assembly loadedAssembly))
Expand Down
Loading