BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Create empty Directory.Build.props to ignore other prop files

Open adamsitnik opened this issue 2 years ago • 5 comments

Context: https://github.com/dotnet/BenchmarkDotNet/issues/2371#issuecomment-1814709479

It should not affect the WASM benchmarks (cc @radical), as they have their own generator:

https://github.com/dotnet/BenchmarkDotNet/blob/630622b6df3192f766ffa03ff07b5086e70cb264/src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs#L52

https://github.com/dotnet/BenchmarkDotNet/blob/630622b6df3192f766ffa03ff07b5086e70cb264/src/BenchmarkDotNet/Templates/WasmCsProj.txt#L3-L5

which links a dedicated props file: https://github.com/dotnet/performance/blob/main/src/benchmarks/micro/MicroBenchmarks.Wasm.props

But I am not sure about dotnet/performance in general, as IIRC the props file there alters some settings like build output path. This is going to require a detailed testing (@cincuranet @LoopedBard3 @DrewScoggins @caaavik-msft @sblom)

fixes #2371

adamsitnik avatar Nov 16 '23 16:11 adamsitnik

Perhaps we could adjust the csproj to make it work, instead of adding a Directory.Build.props?

Old:

<Project Sdk="$SDKNAME$">
  <PropertyGroup>
    <ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
    <ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
  </PropertyGroup>
</Project>

New:

<Project>
  <PropertyGroup>
    <ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
    <ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
  </PropertyGroup>
  
  <Sdk Name="$SDKNAME$">
</Project>

(I forgot where I read that that could work.)

[Edit] Sources: https://github.com/dotnet/msbuild/issues/1680#issuecomment-278503897 https://stackoverflow.com/a/57902835

So, I'm not entirely sure it will work with <Sdk> element (I think it should), it might need to be something like this:

<Project>
  <PropertyGroup>
    <ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
    <ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
  </PropertyGroup>
  
  <Import Project="Sdk.props" Sdk="$SDKNAME$" />
  <Import Project="Sdk.targets" Sdk="$SDKNAME$" />
</Project>

timcassell avatar Dec 04 '23 02:12 timcassell

I'm not entirely sure it will work

The solution that I am proposing here was recommended in https://github.com/dotnet/BenchmarkDotNet/issues/2371#issuecomment-1814709479 by @ViktorHofer who is the MSBuild expert on the .NET Team. It just works.

adamsitnik avatar Dec 04 '23 08:12 adamsitnik

Yeah, you could defer the SDK import but that would make the project file look very different. The Directory.Build.props solution is my preferred approach.

ViktorHofer avatar Dec 04 '23 14:12 ViktorHofer

But I am not sure about dotnet/performance in general, as IIRC the props file there alters some settings like build output path.

That was addressed in #2393. The cli arguments override whatever is in the props, even if we don't ignore it. I'm not sure if other properties are consequential, but this looks good to me otherwise. Should we expose an API for whether or not to ignore props files? [Edit] Actually that could be overridden with a MsBuildArgument, no need for a new API.

timcassell avatar Feb 08 '24 23:02 timcassell

It should not affect the WASM benchmarks (cc @radical), as they have their own generator: ... which links a dedicated props file: https://github.com/dotnet/performance/blob/main/src/benchmarks/micro/MicroBenchmarks.Wasm.props

The directory props are imported before the project, so there it would be importing 2 props files, no? Wouldn't we want to ignore the directory props in the case of wasm also?

Also, the NativeAot generator needs this as well.

timcassell avatar Feb 09 '24 00:02 timcassell