I'm getting the following error when trying to run the benchmark under .net core:
BenchmarkDotNet.Autogenerated.csproj : error NU1201: Project Memoizer.Benchmark.Dotnet is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Project Memoizer.Benchmark.Dotnet supports:
- net462 (.NETFramework,Version=v4.6.2)
- netcoreapp2.0 (.NETCoreApp,Version=v2.0)
The project is configured as following:
<TargetFrameworks>netcoreapp2.0;net462</TargetFrameworks>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
Please note that this very same project was working fine until I upgraded it to netstandard2.0
Hi @CheloXL
In BenchmarkDotNet we generate, build and run new project per every benchmark.
At some point of time we need to choose the target framework moniker (TFM).
When you are running your app with benchmark as .NET Core app, we just check the version of System.Runtime.dll which allows us to decide which version of .NET Core the user is using.
But when you are running your project as classic .NET (.NET 4.6.2 for example), we don't know which TFM to choose, so we use the default - netcoreapp1.1.
My question to you is following: does this problem occur when you run your benchmarks as .NET 4.6.2 only (dotnet run -c Release -f net462)? Or also when you run dotnet run -c Release -f netcoreapp2.0?
It should work fine with dotnet run -c Release -f netcoreapp2.0. For running .NET Core 2.0 benchmarks from .NET 4.6.2 context you have to use custom config:
public class MyConfig : ManualConfig
{
public MyConfig()
{
Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp20)); // .NET Core 2.0
Add(Job.Default.With(CsProjClassicNetToolchain.Net462)); // NET 4.6.2
}
}
If you use such config all your benchmarks are always going to be executed for .NET 4.6.2 and .NET Core 2.0
@CheloXL I added full explanation to our docs. If specifying the toolchain in an explicit way does not help please feel free to reopen this issue.
@adamsitnik Excellent!, thanks. Yes, that works!.
Most helpful comment
Hi @CheloXL
In BenchmarkDotNet we generate, build and run new project per every benchmark.
At some point of time we need to choose the target framework moniker (TFM).
When you are running your app with benchmark as .NET Core app, we just check the version of
System.Runtime.dllwhich allows us to decide which version of .NET Core the user is using.But when you are running your project as classic .NET (.NET 4.6.2 for example), we don't know which TFM to choose, so we use the default -
netcoreapp1.1.My question to you is following: does this problem occur when you run your benchmarks as .NET 4.6.2 only (
dotnet run -c Release -f net462)? Or also when you rundotnet run -c Release -f netcoreapp2.0?It should work fine with
dotnet run -c Release -f netcoreapp2.0. For running .NET Core 2.0 benchmarks from .NET 4.6.2 context you have to use custom config:If you use such config all your benchmarks are always going to be executed for .NET 4.6.2 and .NET Core 2.0