dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Under SDK version >= 8.0.300 many NuGet-related properties are no longer set during evaluation #10504

Open EduardSergeev opened 1 month ago

EduardSergeev commented 1 month ago

Issue Description

There seems to be a breaking change introduced in .NET SDK starting from version 8.0.300: During the evaluation stage of the build many NuGet-related properties are no longer populated, for example $(NugetPackageRoot) or $(NuGetPackageFolder) are missing.

For example when the same project is build using dotnet build -bl the following NuGet* properties are present in Evaluation stage:
With SDK 8.0.206: image

While with SDK 8.0.303 only: image (note missing $(NugetPackageRoot))

I could not find any relevant information regarding this breaking change (our build is broken since we were relying on $(NugetPackageRoot) being set) in release notes so I was wondering if it is undocumented change or a bug? And if there is a way to restore a previous behavior with SDK 8.0.303?

Steps to Reproduce

The following minimal project demonstrates the change in behavior:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
  <Target Name="CheckProperty" BeforeTargets="Restore">
    <Message Text="NugetPackageRoot: $(NugetPackageRoot)" Importance="high" />
  </Target>
</Project>

Expected Behavior

When built using dotnet build command from SDK 8.0.206 the following output is produced:

$ dotnet build
MSBuild version 17.9.8+610b4d3b5 for .NET
  Determining projects to restore...
  NugetPackageRoot: /home/eduard/.nuget/packages/
  Restored /home/eduard/codeir/ir-grpc/src/Test/Test.csproj (in 78 ms).
  Test -> /home/eduard/codeir/ir-grpc/src/Test/bin/Debug/net8.0/Test.dll

The same output is expected under SDK 8.0.300.

Actual Behavior

When built using dotnet build command from SDK 8.0.300:

$ dotnet build
  Determining projects to restore...
  NugetPackageRoot:
  All projects are up-to-date for restore.
  Test -> /home/eduard/codeir/ir-grpc/src/Test/bin/Debug/net8.0/Test.dll

Ask us questions

Is it undocumented change or a bug? And if there is a way to restore a previous behavior with SDK 8.0.303?

EduardSergeev commented 1 month ago

It is probably not a bug and I now suspect that $(NugetPackageRoot) is not supposed to be available before Restore target is executed. Might have been working in previous SDK versions purely by chance. I'll leave my issue as is to confirm.

rainersigwald commented 4 weeks ago

@EduardSergeev Yes, I believe you're seeing results of https://github.com/dotnet/msbuild/pull/9748.