Skip to content

Commit c9548fa

Browse files
authored
chore: fix benchmark testadapter related issues (#2766)
1 parent 3df0f1b commit c9548fa

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

samples/BenchmarkDotNet.Samples/BenchmarkDotNet.Samples.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
</PropertyGroup>
1717
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
1818
<Reference Include="System.Reflection" />
19-
<PackageReference Include="System.Memory" Version="4.6.3" />
2019
</ItemGroup>
2120
<ItemGroup>
22-
<!-- Use v9.0.3 as baseline package for WithNuGet tests -->
23-
<PackageReference Include="System.Collections.Immutable" Version="9.0.3" />
21+
<!-- Use v9.0.0 as baseline package for WithNuGet tests -->
22+
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
2423
</ItemGroup>
2524
<ItemGroup>
2625
<PackageReference Include="System.Drawing.Common" Version="9.0.5" />

samples/BenchmarkDotNet.Samples/IntroNuGet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public Config()
2727
var baseJob = Job.MediumRun;
2828

2929
string[] targetVersions = [
30+
"9.0.0",
3031
"9.0.3",
31-
"9.0.4",
3232
"9.0.5",
3333
];
3434

3535
foreach (var version in targetVersions)
3636
{
3737
AddJob(baseJob.WithNuGet("System.Collections.Immutable", version)
38-
.WithId("v"+version));
38+
.WithId($"v{version}"));
3939
}
4040
}
4141
}

src/BenchmarkDotNet.TestAdapter/BenchmarkEnumerator.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using BenchmarkDotNet.Running;
44
using BenchmarkDotNet.Toolchains;
55
using System;
6-
using System.Collections.Generic;
6+
using System.IO;
77
using System.Linq;
88
using System.Reflection;
99

@@ -21,6 +21,28 @@ internal static class BenchmarkEnumerator
2121
/// <returns>The benchmarks inside the assembly.</returns>
2222
public static BenchmarkRunInfo[] GetBenchmarksFromAssemblyPath(string assemblyPath)
2323
{
24+
#if NET462
25+
// Temporary workaround for BenchmarkDotNet assembly loading issue that occurred under the following conditions:
26+
// 1. Run BenchmarkDotNet.Samples project with following command.
27+
// > dotnet test -c Release --list-tests --framework net462 -tl:off
28+
// 2. When using `BenchmarkDotNet.TestAdapter` package and targeting .NET Framework.
29+
AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) =>
30+
{
31+
if (eventArgs.Name.StartsWith("BenchmarkDotNet, Version="))
32+
{
33+
var baseDir = Path.GetDirectoryName(assemblyPath);
34+
var path = Path.Combine(baseDir, "BenchmarkDotNet.dll");
35+
if (File.Exists(path))
36+
{
37+
return Assembly.LoadFrom(path);
38+
}
39+
}
40+
41+
// Fallback to default assembly resolver
42+
return null;
43+
};
44+
#endif
45+
2446
var assembly = Assembly.LoadFrom(assemblyPath);
2547

2648
var isDebugAssembly = assembly.IsJitOptimizationDisabled() ?? false;

tests/BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks/BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
</ItemGroup>
3131
<ItemGroup>
3232
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
33-
<PackageReference Include="System.Memory" Version="[4.5.5]" />
3433
</ItemGroup>
3534
<ItemGroup>
3635
<Content Include="..\BenchmarkDotNet.IntegrationTests.ManualRunning\xunit.runner.json">

tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
3636
</ItemGroup>
3737
<ItemGroup>
38-
<!-- Use v9.0.3 as baseline package for WithNuGet tests -->
39-
<PackageReference Include="System.Collections.Immutable" Version="[9.0.3]" />
38+
<!-- Use v9.0.0 as baseline package for WithNuGet tests -->
39+
<PackageReference Include="System.Collections.Immutable" Version="[9.0.0]" />
4040
<PackageReference Include="xunit" Version="2.9.3" />
4141
<PackageReference Include="xunit.runner.visualstudio" Version="[2.8.2]">
4242
<PrivateAssets>all</PrivateAssets>

tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
2727
<ProjectReference Include="..\..\src\BenchmarkDotNet.Diagnostics.Windows\BenchmarkDotNet.Diagnostics.Windows.csproj" />
2828
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
29-
<PackageReference Include="System.Memory" Version="4.6.3" />
3029
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
3130
<Reference Include="System.Runtime" />
3231
<Reference Include="System.Threading.Tasks" />

0 commit comments

Comments
 (0)