0

I have a small benchmark project that is targeting netcoreapp2 and net462.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp2;net462</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
  </ItemGroup>

</Project>

However when running this benchmark it only seems to respect the netcoreapp target and not the full framework one. It states that the CLR job was run targeting net472. Could I be doing this wrong or is this an issue? I have targeted only two jobs [CoreJob, ClrJob].

[Host] : .NET Core 2.0.9 (CoreCLR 4.6.26614.01, CoreFX 4.6.26614.01), 64bit RyuJIT Clr : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3394.0 Core : .NET Core 2.0.9 (CoreCLR 4.6.26614.01, CoreFX 4.6.26614.01), 64bit RyuJIT

I have also noticed that even if I remove the explicit job attributes and only target my project to net462 the run summary still shows it executes with net472.

Thulani Chivandikwa
  • 3,402
  • 30
  • 33
  • 2
    Your project can target .NET 4.6.2, but if your system has 4.7.2 installed then that's the version of the runtime. Unlike .NET Core, these are not side-by-side installs; there is only one 4.x CLR runtime, which is upgraded in place. – Jeroen Mostert Apr 28 '19 at 19:43
  • Makes sense, these are the realities that are easy to forget. Thanks for the response. – Thulani Chivandikwa Apr 28 '19 at 21:08

1 Answers1

1

As described in BenchmarkDotNet docs: https://benchmarkdotnet.org/articles/configs/toolchains.html#multiple-frameworks-support

Full .NET Framework always runs every .NET executable using the latest .NET Framework available on a given machine. If you try to run the benchmarks for a few .NET TFMs, they are all going to be executed using the latest .NET Framework from your machine. The only difference is that they are all going to have different features enabled depending on target version they were compiled for. You can read more about this https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/version-compatibility and https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/application-compatibility. This is .NET Framework behavior which can not be controlled by BenchmarkDotNet or any other tool.

Adam Sitnik
  • 1,256
  • 11
  • 15