Skip to content

Commit 008f693

Browse files
authored
Merge pull request #1808 from nunit/issue-1807
Issue 1807
2 parents e8abaea + 89c2f57 commit 008f693

File tree

6 files changed

+49
-167
lines changed

6 files changed

+49
-167
lines changed

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
next-version: 3.21.0
1+
next-version: 3.22.0
22
mode: ContinuousDelivery
33
branches:
44
main:

package-tests.cake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,15 @@ public static class PackageTests
476476
}
477477
});
478478

479-
StandardAndZipLists.Add(new PackageTest(1, "AppContextBaseDirectory_NET80")
480-
{
481-
Description = "Test Setting the BaseDirectory to match test assembly location targeting .NET 8.0",
482-
Arguments = "testdata/net8.0/AppContextTest.dll",
483-
ExpectedResult = new ExpectedResult("Passed")
484-
{
485-
Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("AppContextTest.dll", "netcore-8.0") }
486-
}
487-
});
479+
//StandardAndZipLists.Add(new PackageTest(1, "AppContextBaseDirectory_NET80")
480+
//{
481+
// Description = "Test Setting the BaseDirectory to match test assembly location targeting .NET 8.0",
482+
// Arguments = "testdata/net8.0/AppContextTest.dll",
483+
// ExpectedResult = new ExpectedResult("Passed")
484+
// {
485+
// Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("AppContextTest.dll", "netcore-8.0") }
486+
// }
487+
//});
488488

489489
AllLists.Add(new PackageTest(1, "UnmanagedAssemblyTest")
490490
{

src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
<PackageReference Include="NUnitLite" Version="4.2.2" />
2222
</ItemGroup>
2323

24-
<ItemGroup Condition="'$(TargetFramework)'!='net462'">
25-
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
26-
</ItemGroup>
27-
2824
<ItemGroup>
2925
<Content Include="TestListWithEmptyLine.tst">
3026
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

src/NUnitEngine/nunit.engine.core/Drivers/NUnitNetCore31Driver.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
using System.Linq;
66
using System.Collections.Generic;
77
using System.IO;
8-
using NUnit.Engine.Internal;
98
using System.Reflection;
10-
using NUnit.Engine.Extensibility;
119
using System.Runtime.Loader;
10+
using NUnit.Engine.Internal;
11+
using NUnit.Engine.Extensibility;
1212

1313
namespace NUnit.Engine.Drivers
1414
{
@@ -56,21 +56,24 @@ public class NUnitNetCore31Driver : IFrameworkDriver
5656
/// <returns>An XML string representing the loaded test</returns>
5757
public string Load(string assemblyPath, IDictionary<string, object> settings)
5858
{
59-
//if (assemblyPath.EndsWith("WpfTest.dll"))
60-
// System.Diagnostics.Debugger.Launch();
61-
6259
log.Debug($"Loading {assemblyPath}");
6360
var idPrefix = string.IsNullOrEmpty(ID) ? "" : ID + "-";
6461

6562
assemblyPath = Path.GetFullPath(assemblyPath); //AssemblyLoadContext requires an absolute path
66-
//_assemblyLoadContext = new TestAssemblyLoadContext(assemblyPath);
67-
//_assemblyLoadContext = AssemblyLoadContext.Default;
68-
_assemblyLoadContext = new AssemblyLoadContext(assemblyPath);
69-
_testAssemblyResolver = new TestAssemblyResolver(_assemblyLoadContext, assemblyPath);
7063

7164
try
7265
{
73-
_testAssembly = _assemblyLoadContext.LoadFromAssemblyPath(assemblyPath);
66+
_testAssembly = AssemblyHelper.FindLoadedAssemblyByPath(assemblyPath);
67+
68+
if (_testAssembly != null)
69+
_assemblyLoadContext = AssemblyLoadContext.GetLoadContext(_testAssembly);
70+
else
71+
{
72+
_assemblyLoadContext = new AssemblyLoadContext(Path.GetFileNameWithoutExtension(assemblyPath));
73+
_testAssembly = _assemblyLoadContext.LoadFromAssemblyPath(assemblyPath);
74+
}
75+
76+
_testAssemblyResolver = new TestAssemblyResolver(_assemblyLoadContext, assemblyPath);
7477
}
7578
catch (Exception e)
7679
{

src/NUnitEngine/nunit.engine.core/Internal/AssemblyHelper.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
using System;
44
using System.IO;
5+
using System.Linq;
56
using System.Reflection;
7+
#if NETCOREAPP3_1_OR_GREATER
8+
using System.Runtime.Loader;
9+
#endif
10+
611
namespace NUnit.Engine.Internal
712
{
813
/// <summary>
@@ -69,5 +74,26 @@ public static string GetAssemblyPathFromCodeBase(string codeBase)
6974

7075
return codeBase.Substring(start);
7176
}
77+
78+
// For assemblies already loaded by MTP (net core and above) or by means
79+
public static Assembly FindLoadedAssemblyByPath(string assemblyPath)
80+
{
81+
var full = Path.GetFullPath(assemblyPath);
82+
83+
return AppDomain.CurrentDomain.GetAssemblies()
84+
.FirstOrDefault(a =>
85+
!a.IsDynamic &&
86+
!string.IsNullOrEmpty(a.Location) &&
87+
StringComparer.OrdinalIgnoreCase.Equals(Path.GetFullPath(a.Location), full));
88+
}
89+
90+
public static Assembly FindLoadedAssemblyByName(AssemblyName assemblyName)
91+
{
92+
return AppDomain.CurrentDomain.GetAssemblies()
93+
.FirstOrDefault(a =>
94+
!a.IsDynamic &&
95+
!string.IsNullOrEmpty(a.Location) &&
96+
a.GetName() == assemblyName);
97+
}
7298
}
7399
}

src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyLoadContext.cs

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)