Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of dependencies when loading .NET Core assemblies #1267

Merged
merged 2 commits into from
Nov 13, 2022
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
2 changes: 1 addition & 1 deletion cake/package-checks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ string[] AGENT_FILES = {
"nunit-agent-x86.exe", "nunit-agent-x86.exe.config",
"nunit.engine.core.dll", "nunit.engine.api.dll", "testcentric.engine.metadata.dll"};
string[] AGENT_FILES_NETCORE = {
"nunit-agent.dll", "nunit-agent.dll.config",
"nunit-agent.dll", "nunit-agent.dll.config", "Microsoft.Extensions.DependencyModel.dll",
"nunit.engine.core.dll", "nunit.engine.api.dll", "testcentric.engine.metadata.dll"};
string[] AGENT_PDB_FILES = {
"nunit-agent.pdb", "nunit-agent-x86.pdb", "nunit.engine.core.pdb", "nunit.engine.api.pdb"};
Expand Down
9 changes: 5 additions & 4 deletions cake/package-definitions.cake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void InitializePackageDefinitions(ICakeContext context)
if (IsRunningOnWindows())
StandardRunnerTests.Add(Net60WindowsFormsTest);

if (dotnetX86Available)
// Temporarily disable X86 tests of .NET Core on AppVeyor
if (dotnetX86Available && !BuildSystem.IsRunningOnAppVeyor)
StandardRunnerTests.Add(NetCore31X86Test);

// Tests run for the NETCORE runner package
Expand Down Expand Up @@ -132,12 +133,12 @@ public void InitializePackageDefinitions(ICakeContext context)
checks: new PackageCheck[] {
HasDirectory("NUnit.org").WithFiles("LICENSE.txt", "NOTICES.txt", "nunit.ico"),
HasDirectory("NUnit.org/nunit-console").WithFiles(CONSOLE_FILES).AndFiles(ENGINE_FILES).AndFile("nunit.bundle.addins"),
HasDirectory("NUnit.org/nunit-console/agents/net20").WithFiles("nunit-agent.exe", "nunit-agent.exe.config"),
HasDirectory("NUnit.org/nunit-console/agents/net462").WithFiles("nunit-agent.exe", "nunit-agent.exe.config"),
HasDirectory("NUnit.org/nunit-console/agents/net20").WithFiles(AGENT_FILES),
HasDirectory("NUnit.org/nunit-console/agents/net462").WithFiles(AGENT_FILES),
HasDirectory("NUnit.org/nunit-console/agents/netcoreapp3.1").WithFile("nunit-agent.dll"),
HasDirectory("NUnit.org/nunit-console/agents/net5.0").WithFile("nunit-agent.dll"),
HasDirectory("NUnit.org/nunit-console/agents/net6.0").WithFile("nunit-agent.dll"),
//HasDirectory("NUnit.org/nunit-console/agents/net7.0").WithFile("nunit-agent.dll"),
HasDirectory("NUnit.org/nunit-console/agents/net7.0").WithFile("nunit-agent.dll"),
HasDirectory("Nunit.org/nunit-console/addins").WithFiles("nunit.core.dll", "nunit.core.interfaces.dll", "nunit.v2.driver.dll", "nunit-project-loader.dll", "vs-project-loader.dll", "nunit-v2-result-writer.dll", "teamcity-event-listener.dll")
},
executable: "NUnit.org/nunit-console/nunit3-console.exe",
Expand Down
4 changes: 4 additions & 0 deletions choco/nunit-console-runner.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<file src = "$BASE$agents/netcoreapp3.1/nunit.engine.api.xml" target="tools/agents/netcoreapp3.1" />
<file src = "$BASE$agents/netcoreapp3.1/nunit.engine.core.dll" target="tools/agents/netcoreapp3.1" />
<file src = "$BASE$agents/netcoreapp3.1/testcentric.engine.metadata.dll" target="tools/agents/netcoreapp3.1" />
<file src = "$BASE$agents/netcoreapp3.1/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/netcoreapp3.1" />
<file src = "nunit.agent.addins" target = "tools/agents/netcoreapp3.1" />

<file src = "$BASE$agents/net5.0/nunit-agent.dll" target="tools/agents/net5.0" />
Expand All @@ -81,6 +82,7 @@
<file src = "$BASE$agents/net5.0/nunit.engine.api.xml" target="tools/agents/net5.0" />
<file src = "$BASE$agents/net5.0/nunit.engine.core.dll" target="tools/agents/net5.0" />
<file src = "$BASE$agents/net5.0/testcentric.engine.metadata.dll" target="tools/agents/net5.0" />
<file src = "$BASE$agents/net5.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net5.0" />
<file src = "nunit.agent.addins" target = "tools/agents/net5.0" />

<file src = "$BASE$agents/net6.0/nunit-agent.dll" target="tools/agents/net6.0" />
Expand All @@ -91,6 +93,7 @@
<file src = "$BASE$agents/net6.0/nunit.engine.api.xml" target="tools/agents/net6.0" />
<file src = "$BASE$agents/net6.0/nunit.engine.core.dll" target="tools/agents/net6.0" />
<file src = "$BASE$agents/net6.0/testcentric.engine.metadata.dll" target="tools/agents/net6.0" />
<file src = "$BASE$agents/net6.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net6.0" />
<file src = "nunit.agent.addins" target = "tools/agents/net6.0" />

<file src = "$BASE$agents/net7.0/nunit-agent.dll" target="tools/agents/net7.0" />
Expand All @@ -101,6 +104,7 @@
<file src = "$BASE$agents/net7.0/nunit.engine.api.xml" target="tools/agents/net7.0" />
<file src = "$BASE$agents/net7.0/nunit.engine.core.dll" target="tools/agents/net7.0" />
<file src = "$BASE$agents/net7.0/testcentric.engine.metadata.dll" target="tools/agents/net7.0" />
<file src = "$BASE$agents/net7.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net7.0" />
<file src = "nunit.agent.addins" target = "tools/agents/net7.0" />
</files>
</package>
30 changes: 29 additions & 1 deletion msi/nunit/engine-files.wxi
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@
</ComponentGroup>
<ComponentGroup Id="NETCORE31_AGENT" Directory="NETCORE31_AGENT_DIR">
<Component Id="NUNIT_AGENT_NETCORE31" Location="local" Guid="21E39B4C-07E4-4C38-8F91-7030516127E2">
<File Id="nunit_agent_netcore31.exe"
<File Id="nunit_agent_netcore31.dll"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/netcoreapp3.1/nunit-agent.dll" />
<File Id="nunit_agent_netcore31.dll.config"
Source="$(var.InstallImage)agents/netcoreapp3.1/nunit-agent.dll.config" />
<File Id="nunit_agent_netcore31.deps.json"
Source="$(var.InstallImage)agents/netcoreapp3.1/nunit-agent.deps.json" />
<File Id="nunit_agent_netcore31.runtimeconfig.json"
Expand All @@ -140,6 +142,11 @@
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/netcoreapp3.1/testcentric.engine.metadata.dll" />
</Component>
<Component Id="NUNIT_AGENT_NETCORE31_DEPENDENCY_MODEL" Location="local" Guid="6A33A615-BCD2-411C-B3A8-95BF5829C8CA">
<File Id="Microsoft.Extensions.DependencyModel.netcore31.dll"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/netcoreapp3.1/Microsoft.Extensions.DependencyModel.dll" />
</Component>
<Component Id="NUNIT_AGENT_ADDINS_NETCORE31" Location="local" Guid="">
<File Id="nunit.agent.netcore31.addins" Source="../resources/nunit.agent.addins" />
</Component>
Expand All @@ -149,6 +156,8 @@
<File Id="nunit_agent_net50.exe"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net5.0/nunit-agent.dll" />
<File Id="nunit_agent_net50.dll.config"
Source="$(var.InstallImage)agents/net5.0/nunit-agent.dll.config" />
<File Id="nunit_agent_net50.deps.json"
Source="$(var.InstallImage)agents/net5.0/nunit-agent.deps.json" />
<File Id="nunit_agent_net50.runtimeconfig.json"
Expand All @@ -171,6 +180,11 @@
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net5.0/testcentric.engine.metadata.dll" />
</Component>
<Component Id="NUNIT_AGENT_NET50_DEPENDENCY_MODEL" Location="local" Guid="EF4F5A8A-AC06-4228-97C0-DBD8B7E1C50B">
<File Id="Microsoft.Extensions.DependencyModel.net50.dll"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net5.0/Microsoft.Extensions.DependencyModel.dll" />
</Component>
<Component Id="NUNIT_AGENT_ADDINS_NET50" Location="local" Guid="">
<File Id="nunit.agent.net50.addins" Source="../resources/nunit.agent.addins" />
</Component>
Expand All @@ -180,6 +194,8 @@
<File Id="nunit_agent_net60.exe"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net6.0/nunit-agent.dll" />
<File Id="nunit_agent_net60.dll.config"
Source="$(var.InstallImage)agents/net6.0/nunit-agent.dll.config" />
<File Id="nunit_agent_net60.deps.json"
Source="$(var.InstallImage)agents/net6.0/nunit-agent.deps.json" />
<File Id="nunit_agent_net60.runtimeconfig.json"
Expand All @@ -202,6 +218,11 @@
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net6.0/testcentric.engine.metadata.dll" />
</Component>
<Component Id="NUNIT_AGENT_NET60_DEPENDENCY_MODEL" Location="local" Guid="EFD82EAE-A38E-45E0-944B-A776F7353100">
<File Id="Microsoft.Extensions.DependencyModel.net60.dll"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net6.0/Microsoft.Extensions.DependencyModel.dll" />
</Component>
<Component Id="NUNIT_AGENT_ADDINS_NET60" Location="local" Guid="">
<File Id="nunit.agent.net60.addins" Source="../resources/nunit.agent.addins" />
</Component>
Expand All @@ -211,6 +232,8 @@
<File Id="nunit_agent_net70.exe"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net7.0/nunit-agent.dll" />
<File Id="nunit_agent_net70.dll.config"
Source="$(var.InstallImage)agents/net7.0/nunit-agent.dll.config" />
<File Id="nunit_agent_net70.deps.json"
Source="$(var.InstallImage)agents/net7.0/nunit-agent.deps.json" />
<File Id="nunit_agent_net70.runtimeconfig.json"
Expand All @@ -234,6 +257,11 @@
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net6.0/testcentric.engine.metadata.dll" />
</Component>
<Component Id="NUNIT_AGENT_NET70_DEPENDENCY_MODEL" Location="local" Guid="B5469699-3822-45DA-889F-BAF312945A24">
<File Id="Microsoft.Extensions.DependencyModel.net70.dll"
ProcessorArchitecture="msil"
Source="$(var.InstallImage)agents/net6.0/Microsoft.Extensions.DependencyModel.dll" />
</Component>
<Component Id="NUNIT_AGENT_ADDINS_NET70" Location="local" Guid="">
<File Id="nunit.agent.net70.addins" Source="../resources/nunit.agent.addins" />
</Component>
Expand Down
3 changes: 2 additions & 1 deletion nuget/engine/nunit.engine.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
<file src="agents/netcoreapp3.1/nunit.engine.core.pdb" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/nunit.engine.api.dll" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/nunit.engine.api.pdb" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/testcentric.engine.metadata.dll" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/testcentric.engine.metadata.dll" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/netcoreapp3.1" />
<file src="../../../../../nuget/nunit.agent.addins" target="contentFiles/any/agents/netcoreapp3.1"/>

<file src="../../../../../nuget/engine/build/**/*" target="build" />
Expand Down
3 changes: 2 additions & 1 deletion nuget/runners/nunit.console-runner.netcore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<file src="nunit.engine.api.pdb" target="tools/net6.0/any" />
<file src="nunit.engine.api.xml" target="tools/net6.0/any" />
<file src="testcentric.engine.metadata.dll" target="tools/net6.0/any" />

<file src="Microsoft.Extensions.DependencyModel.dll" target="tools/net6.0/any" />

<file src="../../../../../../nuget/runners/nunit.console.nuget.addins" target="tools/net6.0/any"/>
<file src="../../../../../../nuget/runners/DotnetToolSettings.xml" target="tools/net6.0/any"/>
<file src="../../../../../../nunit_256.png" target="images"/>
Expand Down
7 changes: 5 additions & 2 deletions nuget/runners/nunit.console-runner.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<file src="agents/netcoreapp3.1/nunit.engine.core.dll" target="tools/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/nunit.engine.core.pdb" target="tools/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/testcentric.engine.metadata.dll" target="tools/agents/netcoreapp3.1" />
<file src="agents/netcoreapp3.1/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/netcoreapp3.1" />
<file src="../../../../../../nuget/nunit.agent.addins" target="tools/agents/netcoreapp3.1"/>

<file src="agents/net5.0/nunit-agent.dll" target="tools/agents/net5.0" />
Expand All @@ -93,7 +94,8 @@
<file src="agents/net5.0/nunit.engine.core.dll" target="tools/agents/net5.0" />
<file src="agents/net5.0/nunit.engine.core.pdb" target="tools/agents/net5.0" />
<file src="agents/net5.0/testcentric.engine.metadata.dll" target="tools/agents/net5.0" />
<file src="../../../../../../nuget/nunit.agent.addins" target="tools/agents/net5.0"/>
<file src="agents/net5.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net5.0" />
<file src="../../../../../../nuget/nunit.agent.addins" target="tools/agents/net5.0" />

<file src="agents/net6.0/nunit-agent.dll" target="tools/agents/net6.0" />
<file src="agents/net6.0/nunit-agent.pdb" target="tools/agents/net6.0" />
Expand All @@ -106,6 +108,7 @@
<file src="agents/net6.0/nunit.engine.core.dll" target="tools/agents/net6.0" />
<file src="agents/net6.0/nunit.engine.core.pdb" target="tools/agents/net6.0" />
<file src="agents/net6.0/testcentric.engine.metadata.dll" target="tools/agents/net6.0" />
<file src="agents/net6.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net6.0" />
<file src="../../../../../../nuget/nunit.agent.addins" target="tools/agents/net6.0"/>

<file src="agents/net7.0/nunit-agent.dll" target="tools/agents/net7.0" />
Expand All @@ -119,7 +122,7 @@
<file src="agents/net7.0/nunit.engine.core.dll" target="tools/agents/net7.0" />
<file src="agents/net7.0/nunit.engine.core.pdb" target="tools/agents/net7.0" />
<file src="agents/net7.0/testcentric.engine.metadata.dll" target="tools/agents/net7.0" />
<file src="agents/net7.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net7.0" />
<file src="../../../../../../nuget/nunit.agent.addins" target="tools/agents/net7.0"/>

</files>
</package>
2 changes: 0 additions & 2 deletions src/NUnitEngine/aspnetcore-test/aspnetcore-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<OutputType>Library</OutputType>
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion src/NUnitEngine/mock-assembly-x86/mock-assembly-x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<AssemblyOriginatorKeyFile>..\..\nunit.snk</AssemblyOriginatorKeyFile>
<PlatformTarget>x86</PlatformTarget>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/NUnitEngine/mock-assembly/mock-assembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\nunit.snk</AssemblyOriginatorKeyFile>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/NUnitEngine/notest-assembly/notest-assembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<PropertyGroup>
<RootNamespace>notest_assembly</RootNamespace>
<TargetFrameworks>net35;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class NUnitNetCore31Driver : IFrameworkDriver
Assembly _frameworkAssembly;
object _frameworkController;
Type _frameworkControllerType;
CustomAssemblyLoadContext _assemblyLoadContext;
TestAssemblyLoadContext _assemblyLoadContext;

/// <summary>
/// An id prefix that will be passed to the test framework and used as part of the
Expand All @@ -58,13 +58,7 @@ public string Load(string assemblyPath, IDictionary<string, object> settings)
var idPrefix = string.IsNullOrEmpty(ID) ? "" : ID + "-";

assemblyPath = Path.GetFullPath(assemblyPath); //AssemblyLoadContext requires an absolute path
_assemblyLoadContext = new CustomAssemblyLoadContext(assemblyPath);

_assemblyLoadContext.Resolving += (context, assemblyName) =>
{
var calc = context as CustomAssemblyLoadContext;
return calc?.LoadFallback(assemblyName);
};
_assemblyLoadContext = new TestAssemblyLoadContext(assemblyPath);

try
{
Expand Down

This file was deleted.

Loading