sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Microsoft.Net.Sdk.Compilers.Toolset download check fails because NuGetPackageRoot is unset in some scenarios

Open jjonescz opened this issue 6 months ago • 5 comments

Related to https://github.com/dotnet/sdk/issues/41791 and https://github.com/dotnet/sdk/issues/42087.

The error is:

NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild.

It happens because $(NuGetPackageRoot) is unset, hence <RoslynTargetsPath>$(NuGetPackageRoot)\microsoft.net.sdk.compilers.toolset\$(NETCoreSdkVersion)</RoslynTargetsPath> points to an invalid location, hence the download check fails.

For example, $(NuGetPackageRoot) is unset in these scenarios:

  • msbuild.exe '/t:Restore;Build' (but it's fine when running with /restore /t:Build)
    • https://github.com/dotnet/msbuild/issues/9553
    • https://github.com/dotnet/msbuild/issues/2811
  • in the inner build started by task GenerateTemporaryTargetAssembly when building WPF on .NET Framework

In the following, the toolset package download was completely disabled likely because it was failing due to this bug:

  • https://github.com/dotnet/winforms/pull/11878
  • https://github.com/dotnet/sdk/pull/42699/commits/e9e9566478c56b2c1f223bfe2de2fb9dc04796e9

Similar issue:

  • https://github.com/dotnet/msbuild/issues/10504

A workaround for this issue is being added in https://github.com/dotnet/sdk/pull/42860.

jjonescz avatar Aug 27 '24 07:08 jjonescz