BenchmarkDotNet
BenchmarkDotNet copied to clipboard
Benchmarks referencing TestAdapter fail to build with OS-specific TFMs
Attempting to use the TestAdapter with a project using an OS-specific TFM such as
<TargetFramework>net8.0-windows</TargetFramework>
gives an error when trying to run the benchmark through the test explorer:
D:\BenchmarkTest\bin\x64\Release\2cab09cb-454b-49b3-b8fb-d898d2a7f2df\BenchmarkDotNet.Autogenerated.csproj : error NU1201: Project BenchmarkTest is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project BenchmarkTest supports: net8.0-windows7.0 (.NETCoreApp,Version=v8.0)
I tried to add a custom entry point and config to specify the TFM explicitly, but got the same error:
public static class Program
{
sealed class CustomConfig : ManualConfig
{
public CustomConfig()
{
AddJob(Job.ShortRun.WithToolchain(CsProjCoreToolchain.From(
new NetCoreAppSettings(
targetFrameworkMoniker: "net8.0-windows",
runtimeFrameworkVersion: null,
name: "net8.0-windows")))
.AsDefault());
AddLogger(ConsoleLogger.Default);
AddColumn(TargetMethodColumn.Method, StatisticColumn.Iterations, StatisticColumn.Mean, StatisticColumn.Max);
AddColumnProvider(DefaultColumnProviders.Params);
}
}
static void Main(string[] args)
{
CustomConfig config = new();
_ = BenchmarkRunner.Run(typeof(Program).Assembly, config, args);
}
}
You can use a Config
attribute https://benchmarkdotnet.org/articles/features/vstest.html#setting-a-default-configuration
Or you can disable the generated entry point <GenerateProgramFile>false</GenerateProgramFile>
@timcassell Ah, yup, the Config attribute does work, but I was trying to do it just via a custom entry point to avoid hitting problems from #2500. If I do both the Config attribute and <GenerateProgramFile>false</GenerateProgramFile>
then everything is OK - my bad
cc @caaavik-msft