Skip to content

ImportDirectoryBuildProps not working in BenchmarkDotNet.Autogenerated.csproj #2722

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

Closed
Titas22 opened this issue Apr 26, 2025 · 0 comments
Closed

Comments

@Titas22
Copy link

Titas22 commented Apr 26, 2025

Hi,

I'm trying to set up benchmarks for a library projects where I use the simplified artifacts output layout and Directory.Build.props at the root where I define multiple target frameworks for the library (including .NET Standard 2.0).

The issue is that when I build the benchmark project for .NET 8, its auto generated project includes the same Directory.Build.props at the root (as that's the closest one to the .artifacts folder, it starts targeting .NET Standard 2.0 and I get an error:

// Validating benchmarks:
// ***** BenchmarkRunner: Start   *****
// ***** Found 2 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start   *****
// start dotnet  restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true /p:IntermediateOutputPath="C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0\obj\Release\net8.0/" /p:OutDir="C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0\bin\Release\net8.0/" /p:OutputPath="C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0\bin\Release\net8.0/" in C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0
// command took 1.58 sec and exited with 1
// ***** Done, took 00:00:01 (1.67 sec)   *****
// Found 2 benchmarks:
//   BenchmarkClass.Scenario1: DefaultJob
//   BenchmarkClass.Scenario2: DefaultJob

Setup power plan (GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c FriendlyName: High performance)
// Build Error: Standard output:

 Standard error:
   Determining projects to restore...
C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0\BenchmarkDotNet.Autogenerated.csproj : error NU1201: Project SampleBenchmark is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project SampleBenchmark supports: net8.0 (.NETCoreApp,Version=v8.0) [TargetFramework=net8.0]
  Failed to restore C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0\BenchmarkDotNet.Autogenerated.csproj (in 369 ms).
  1 of 2 projects are up-to-date for restore.

// BenchmarkDotNet has failed to build the auto-generated boilerplate code.
// It can be found in C:\Users\titas\Code\BenchmarkDotNet-BuildDirectoryPropsIssue\.artifacts\bin\SampleBenchmark\debug_win-x64\61614065-6a51-405e-b88a-4650444e5ee0
// Please follow the troubleshooting guide: https://benchmarkdotnet.org/articles/guides/troubleshooting.html

I've set up a minimal example to illustrate it here


Now one possible solution I've found that works for me is to define the framework targets in Directory.Build.props in a conditional PropertyGroup:

<PropertyGroup Condition="'$(MSBuildProjectName)' != 'BenchmarkDotNet.Autogenerated'">

But I feel like the benchmarking library should handle this somehow.

What I've seen is that the auto generated BenchmarkDotNet.Autogenerated.csproj contains:

<ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
<ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>

which presumably should avoid importing the Directory.Build.props but it seems that it gets imported before the .csproj which makes them not do anything (if they are indeed expected to).

Would it be possible to somehow pass in ImportDirectoryBuildProps=false and ImportDirectoryBuildTargets=false as part of the build command to make sure they are defined early enough? Not sure if that would work but just an idea

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

2 participants