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

Benchmarks referencing TestAdapter fail to build with OS-specific TFMs #2501

Open
molesmoke opened this issue Jan 8, 2024 · 4 comments
Open

Comments

@molesmoke
Copy link

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)

@molesmoke
Copy link
Author

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);
    }
}

@timcassell
Copy link
Collaborator

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>

@molesmoke
Copy link
Author

@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

@adamsitnik
Copy link
Member

cc @caaavik-msft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants