Benchmarkdotnet: Allow benchmarking .NET Core Desktop apps

Created on 14 Feb 2019  路  3Comments  路  Source: dotnet/BenchmarkDotNet

I'd like to perf test some of the new desktop sdk stuf (like WPF on .NET Core), but when referencing the sdk, benchmarkdotnet seems to be generating a project that doesn't work during benchmark.

I've shared a repro here that tries to compare net471 to netcoreappp3.0:

https://github.com/dotMorten/WPFBenchmarkTests/tree/c92fec08ce09e8cf852927ea4d6f012b5460428b

In debug mode it just runs the test manually without the runner and confirms things work just fine. But when running in release BenchmarkDotNet generates a new project, and this project fails to execute with:

// **************************
// Benchmark: BenchmarkTests.LoadImageControl: Job-VWWZKF(Toolchain=.NET Core 3.0)
// *** Execute ***
// Launch: 1 / 1
// BeforeAnythingElse

// Benchmark Process Environment Information:
// Runtime=.NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
// GC=Concurrent Workstation
// Job: DefaultJob


System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
   at WPFUIBenchmark.Program.BenchmarkTests.Setup()
   at BenchmarkDotNet.Engines.EngineFactory.CreateReadyToRun(EngineParameters engineParameters)
   at BenchmarkDotNet.Autogenerated.Runnable_0.Run(IHost host, String benchmarkName) in D:\GitHub\dotMorten\WPFBenchmarkTests\src\bin\Release\netcoreapp3.0\47f57267-da28-484f-9952-cb714fb6acff\47f57267-da28-484f-9952-cb714fb6acff.notcs:line 145
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at BenchmarkDotNet.Autogenerated.UniqueProgramName.AfterAssemblyLoadingAttached(String[] args) in D:\GitHub\dotMorten\WPFBenchmarkTests\src\bin\Release\netcoreapp3.0\47f57267-da28-484f-9952-cb714fb6acff\47f57267-da28-484f-9952-cb714fb6acff.notcs:line 60
// AfterAll
ExitCode != 0
No more Benchmark runs will be launched as NO measurements were obtained from the previous run!

It seems the generated project doesn't use the Microsoft.NET.Sdk.WindowsDesktop SDK, but I even tried hacking that into the csproj template BenchmarkDotNet uses, but I still didn't have much luck.
I'm curious if this is impossible to pull off with BenchmarkDotNet at this point, or if there's a way to "hack" it in to get it running?

Toolchains enhancement

All 3 comments

I am able to reproduce, lookin into the auto-generated .csproj to figure out what is wrong

Ok, so the .csproj that we auto-generate imports wrong Sdk:

<Project ToolsVersion="15.0">
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>

while it should be:

<Project Sdk="Microsoft.NET.Sdk">
  <Import Sdk="Microsoft.NET.Sdk.WindowsDesktop" Project="Sdk.props" />

  <Import Sdk="Microsoft.NET.Sdk.WindowsDesktop" Project="Sdk.targets" />
</Project>

now I need to try a clean fix

I have a PR with the fix #1066

I will do some testing and send a PR to your repo.

Was this page helpful?
0 / 5 - 0 ratings