dotnet / BenchmarkDotNet

Powerful .NET library for benchmarking
https://benchmarkdotnet.org
MIT License
10.42k stars 957 forks source link

Failed to build when using central package version management (CPVM) #2213

Open flobernd opened 1 year ago

flobernd commented 1 year ago

My project is using the new central package version management feature (Directory.Packages.props in the root directory). If this feature is enabled, it's not allowed to specify a package version in a <PackageReference> tag.

BenchmarkDotNet build fails, because of this:

 Standard error:
   Determining projects to restore...
[...]\bin\Release\net7\a26f5fd8-3b2f-4716-a61f-af4e51ccb248\BenchmarkDotNet.Autogenerated.csproj : error NU1008: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: Microsoft.DotNet.ILCompiler.

It can be fixed on your side by auto-generating a Directory.Packages.props in the output directory (e.g. \bin\Release\net7\a26f5fd8-3b2f-4716-a61f-af4e51ccb248 in this example) with the following content:

<!-- https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
  </PropertyGroup>
</Project>

This will disable the CPVM feature for all projects inside the output directory (recursively).

adamsitnik commented 1 year ago

Hi @flobernd

Please send a PR with the fix, you most likely need to add this setting in the following two places:

https://github.com/dotnet/BenchmarkDotNet/blob/d383135825b66a99447bf4460255ed694375ca47/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs#L142

https://github.com/dotnet/BenchmarkDotNet/blob/d383135825b66a99447bf4460255ed694375ca47/src/BenchmarkDotNet/Templates/CsProj.txt#L29

paulomorgado commented 1 month ago

@adamsitnik,

Is this still an issue?

adamsitnik commented 1 month ago

Is this still an issue?

Most likely yes as we have not changed anything on our side.

paulomorgado commented 1 month ago

Anything I can do to move this forward?

paulomorgado commented 1 month ago

This might require BenchmarkDotNet to support central package management, as projects won't have versions in package references.

Or is it an issue only for the BenchmarkDotNet project?

Is there a way to get a binlog from the build BenchmarkDotNet is doing?

adamsitnik commented 1 month ago

Anything I can do to move this forward?

You would need to be able to reproduce it by using CPVM and then propose a fix. In theory what I posted here should be enough: https://github.com/dotnet/BenchmarkDotNet/issues/2213#issuecomment-1335032942, but we need to test it.

Is there a way to get a binlog from the build BenchmarkDotNet is doing?

If you pass --generateBinLog BDN should generate the bin log.

https://github.com/dotnet/BenchmarkDotNet/blob/0275649d350bcdc6953215598eca775b4882ece5/src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs#L176-L177