msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Bootstrap MSBuild unable to build console projects: unable to resolve workload SDKs

Open KirillOsenkov opened this issue 3 years ago • 10 comments

Prep a bootstrap MSBuild layout using build /p:CreateBootstrap=true or download the one I used from: https://kirillosenkovfiles.blob.core.windows.net/kirillosenkovblob/msbuild.17.3.1.zip

Be on an empty Windows machine, such as Windows Sandbox VM

Create and build a new C# console app targeting net472

Expected: builds successfully

Actual:

Build FAILED.

  C:\Users\WDAGUtilityAccount\AppData\Local\Bootstrap\MSBuild\Sdks\Microsoft.NET.Sdk\targets\Mic
rosoft.NET.Sdk.ImportWorkloads.props(14,3): error : Unable to locate the .NET SDK. Check that it is installed and that
the version specified in global.json (if any) matches the installed version.
  C:\Users\WDAGUtilityAccount\AppData\Local\Bootstrap\MSBuild\Sdks\Microsoft.NET.Sdk\targets\Mic
rosoft.NET.Sdk.ImportWorkloads.targets(16,3): error : Unable to locate the .NET SDK. Check that it is installed and tha
t the version specified in global.json (if any) matches the installed version.

The two SDKs it can't resolve:

Resolving SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator'...
Resolving SDK 'Microsoft.NET.SDK.WorkloadManifestTargetsLocator'...

First off, the error messages are inadequate - they don't mention the SDK reference that failed to resolve.

Both of these are supposed to resolve from: https://github.com/dotnet/sdk/blob/3dc5e528fffc050cace4cff8bc32954eb33f0455/src/Resolvers/Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver/CachingWorkloadResolver.cs#L121-L136

However on an empty machine with just the xcopied MSBuild something goes awry apparently and it fails with the obscure messages above.

Until recently, the bootstrap MSBuild was xcopyable, meaning it used to build desktop-targeting projects on a completely empty Windows machine.

At some point this regressed. It is crucial that we continue to be able to have xcopyable MSBuild and we should move towards making MSBuild more portable, not less.

KirillOsenkov avatar Sep 20 '22 03:09 KirillOsenkov

Nothing seems to be logging anything into the SdkLogger.

This is never used for anything: https://github.com/dotnet/msbuild/blob/cc3db358d34ad4cd1ec0c67e17582d7ca2a15040/src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs#L259

KirillOsenkov avatar Sep 20 '22 03:09 KirillOsenkov

It would be nice to prioritize this, because every release MSBuild ships, it ships being unable to work on an empty machine without the SDK installed. If it continues to be broken, we will be unable to just walk up to the MSBuild repo, build bootstrap and expect that it just works on any machine.

I normally like building and archiving bootstrapped MSBuild for every release, but the last working one I have is from 17.2 or something. This is also useful for bisecting, to answer questions like "which MSBuild release did this break in?"

KirillOsenkov avatar Sep 13 '23 23:09 KirillOsenkov

@marcpopMSFT

KirillOsenkov avatar Sep 13 '23 23:09 KirillOsenkov

@baronfel I'd love to see this fixed at some point

KirillOsenkov avatar Dec 20 '23 02:12 KirillOsenkov

Latest messages from bootstrap MSBuild 17.8.3:

C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\MSBuild\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props (14,3): Could not resolve SDK "Microsoft.NET.SDK.WorkloadAutoImportPropsLocator". Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
  Unable to locate the .NET SDK. Check that it is installed, your PATH is configured for the correct architecture, and that the version specified in global.json (if any) matches the installed version.
  The NuGetSdkResolver did not resolve this SDK because there was no version specified in the project or global.json.
  MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.SDK.WorkloadAutoImportPropsLocator" because directory "C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\MSBuild\Sdks\Microsoft.NET.SDK.WorkloadAutoImportPropsLocator\Sdk" did not exist.
C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\MSBuild\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets (16,3): Could not resolve SDK "Microsoft.NET.SDK.WorkloadManifestTargetsLocator". Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
  Unable to locate the .NET SDK. Check that it is installed, your PATH is configured for the correct architecture, and that the version specified in global.json (if any) matches the installed version.
  The NuGetSdkResolver did not resolve this SDK because there was no version specified in the project or global.json.
  MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.SDK.WorkloadManifestTargetsLocator" because directory "C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\MSBuild\Sdks\Microsoft.NET.SDK.WorkloadManifestTargetsLocator\Sdk" did not exist.

KirillOsenkov avatar Dec 20 '23 03:12 KirillOsenkov

Related to #6566, maybe https://github.com/dotnet/msbuild/blob/5cf78584f998e524374758c5798b7054bf2595e9/eng/BootStrapMSBuild.targets#L258-L260 should apply to netfx MSBuild too.

rainersigwald avatar Dec 20 '23 12:12 rainersigwald

@JanKrivanek if there was one MSBuild issue that I'd love to see fixed the most, it's this one

It's super important for standalone bootstrap MSBuild to be able to build projects, and it's currently not working. It's super important to be able to check out any commit of MSBuild, build bootstrap and be able to use that MSBuild to build real projects.

KirillOsenkov avatar Mar 21 '24 18:03 KirillOsenkov

I'll venmo $100 to whoever fixes this.

KirillOsenkov avatar May 03 '24 21:05 KirillOsenkov

This is a long standing issue and I just wanted to dig what is this about(also good motivator 💰 😄 ) I did not understand the full picture but I just download the source of this repo to a new(empty) windows installation and ran the build command, got the error below

  Microsoft.Build.Utilities -> C:\Users\vboxuser\msbuild-main\artifacts\bin\Microsoft.Build.Utilities\Debug\netstandard2.0\Microsoft.Build.Utilities.Core.dll
C:\Users\vboxuser\msbuild-main\.tools\msbuild\17.8.5\tools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3345,5): error MSB3821: Couldn't process file system.design\system.design.txt due to its being in the Internet or Res
tricted zone or having the mark of the web on the file. Remove the mark of the web if you want to process these files. [C:\Users\vboxuser\msbuild-main\src\Tasks\Microsoft.Build.Tasks.csproj::TargetFramework=net8.0]
  StringTools -> C:\Users\vboxuser\msbuild-main\artifacts\bin\StringTools\Debug\net35\Microsoft.NET.StringTools.net35.dll
  StringTools.UnitTests -> C:\Users\vboxuser\msbuild-main\artifacts\bin\StringTools.UnitTests\Debug\net472\Microsoft.NET.StringTools.UnitTests.dll
  Microsoft.Build.UnGAC -> C:\Users\vboxuser\msbuild-main\artifacts\bin\Microsoft.Build.UnGAC\Debug\net45\Microsoft.Build.UnGAC.exe
  StringTools.UnitTests -> C:\Users\vboxuser\msbuild-main\artifacts\bin\StringTools.UnitTests\Debug\net8.0\Microsoft.NET.StringTools.UnitTests.dll
  StringTools.UnitTests.net35 -> C:\Users\vboxuser\msbuild-main\artifacts\bin\StringTools.UnitTests.net35\Debug\net472\Microsoft.NET.StringTools.net35.UnitTests.dll
C:\Users\vboxuser\msbuild-main\.tools\msbuild\17.8.5\tools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3345,5): error MSB3091: Task failed because "resgen.exe" was not found, or the correct Microsoft Windows SDK is not i
nstalled. The task is looking for "resgen.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx3
5Tools-x86. You may be able to solve the problem by doing one of the following:  1) Install the Microsoft Windows SDK.  2) Install Visual Studio 2010.  3) Manually set the above registry key to the correct location.  4) Pass the correct
 location into the "ToolPath" parameter of the task. [C:\Users\vboxuser\msbuild-main\src\MSBuildTaskHost\MSBuildTaskHost.csproj]
  StringTools.Benchmark -> C:\Users\vboxuser\msbuild-main\artifacts\bin\StringTools.Benchmark\Debug\net472\StringTools.Benchmark.exe
  StringTools.Benchmark -> C:\Users\vboxuser\msbuild-main\artifacts\bin\StringTools.Benchmark\Debug\net8.0\StringTools.Benchmark.dll

Build FAILED.

C:\Users\vboxuser\msbuild-main\src\Directory.Build.targets(137,5): error : TlbExp was not found. Ensure that you have installed everything from .vsconfig. If you have, please report a bug to MSBuild. [C:\Users\vboxuser\msbuild-main\src\
Framework\Microsoft.Build.Framework.csproj::TargetFramework=net472]
C:\Users\vboxuser\msbuild-main\.tools\msbuild\17.8.5\tools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3345,5): error MSB3821: Couldn't process file system.design\system.design.txt due to its being in the Internet or Res
tricted zone or having the mark of the web on the file. Remove the mark of the web if you want to process these files. [C:\Users\vboxuser\msbuild-main\src\Tasks\Microsoft.Build.Tasks.csproj::TargetFramework=net8.0]
C:\Users\vboxuser\msbuild-main\.tools\msbuild\17.8.5\tools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3345,5): error MSB3091: Task failed because "resgen.exe" was not found, or the correct Microsoft Windows SDK is not i
nstalled. The task is looking for "resgen.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx3
5Tools-x86. You may be able to solve the problem by doing one of the following:  1) Install the Microsoft Windows SDK.  2) Install Visual Studio 2010.  3) Manually set the above registry key to the correct location.  4) Pass the correct
 location into the "ToolPath" parameter of the task. [C:\Users\vboxuser\msbuild-main\src\MSBuildTaskHost\MSBuildTaskHost.csproj]
    0 Warning(s)
    3 Error(s)

Time Elapsed 00:00:25.76
Build failed with exit code 1. Check errors above.

Sorry for my ignorance. Are we trying to fix the this build.cmd process or are we trying to fix the dotnet project generator ?

ozkanpakdil avatar May 04 '24 14:05 ozkanpakdil

@ozkanpakdil neither, you should be able to build this repo either way. Try cloning the repo instead of downloading a zip file (or Unblock the zip file in the file properties before extracting the files). The scenario to be fixed is described in the OP, it's running the msbuild itself to compile a blank project.

I run into this issue myself trying to compile a .NET project on a machine that has .NET SDK binaries only, i.e. not installed by the installer.

miloush avatar May 04 '24 15:05 miloush

I run into this issue myself trying to compile a .NET project on a machine that has .NET SDK binaries only, i.e. not installed by the installer.

@miloush Can you elaborate please? The SDK zips should work fine.

rainersigwald avatar May 06 '24 20:05 rainersigwald

I download the SDK binaries and put them in a folder. Then when I want to compile a project either I can use MSBuildSDKsPath environment to point to the folder (for the default resolver), or I explicitly include the SDK props and targets files via <Import />.

Either way, I get

...\dotnet-sdk-8.0.204-win-x64\sdk\8.0.204\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props (14,3): Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
...\dotnet-sdk-8.0.204-win-x64\sdk\8.0.204\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props (14,38): error MSB4236: The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found.

miloush avatar May 06 '24 20:05 miloush

Using what MSBuild, @miloush?

rainersigwald avatar May 06 '24 20:05 rainersigwald

Any recent MSBuild since 2022, specifically I think bootstrap built from 17.8.3

KirillOsenkov avatar May 06 '24 20:05 KirillOsenkov

@KirillOsenkov AFAICT @miloush is describing a different problem. You are wanting #10112.

rainersigwald avatar May 06 '24 20:05 rainersigwald

Hm, appears to be MSBuild version 17.3.1+2badb37d1 for .NET Framework

miloush avatar May 06 '24 20:05 miloush

@miloush that is old to use a new SDK like 8.0.204. I don't think I'd expect that combination to work.

In addition if you want to use a .NET Framework MSBuild (VS/msbuild.exe) with a zip SDK, I think you'd need to set some of the more specific environment variables (DOTNET_ROOT maybe, or DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR).

rainersigwald avatar May 06 '24 21:05 rainersigwald

@rainersigwald when I install the SDK, I get

Microsoft.NET.Sdk.ImportWorkloads.targets (16,3): Version 8.0.204 of the .NET SDK requires at least version 17.8.3
of MSBuild. The current available version of MSBuild is 17.3.1.46901. Change the .NET SDK specified in global.json
to an older version that requires the MSBuild version currently available

so I would expect that too without installation, instead I get the unresolved SDKs error above. I will try to see how it looks like with a newer msbuild.

miloush avatar May 06 '24 22:05 miloush

It works! But also need to drop the sentinel for amd64. I can do it.

KirillOsenkov avatar May 07 '24 06:05 KirillOsenkov

Setting MSBuildEnableWorkloadResolver to false works as well.

KirillOsenkov avatar May 07 '24 06:05 KirillOsenkov

I am pretty sure I tried to set MSBuildEnableWorkloadResolver in the project and it wasn't helpful. If I remember correctly, the build succeeded, but no output was produced.

miloush avatar May 07 '24 08:05 miloush

Sorry about the delay, I have the setup back. No SDK installed, only 8.0 ZIP. Upgraded to MSBuild version 17.8.3+195e7f5a3 for .NET Framework.

MSBuildSDKsPath set to ...\dotnet-sdk-8.0.204-win-x64\sdk\8.0.204\Sdks\

The compilation results in error:

..\dotnet-sdk-8.0.204-win-x64\sdk\8.0.204\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props (14,38): error MSB4236: The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found.

miloush avatar May 16 '24 14:05 miloush

@miloush don't set MSBuildSDKsPath; it doesn't do what you want. Instead set the .NET SDK resolver environment variables https://github.com/dotnet/msbuild/issues/7988#issuecomment-2096943886.

rainersigwald avatar May 16 '24 14:05 rainersigwald

OK DOTNET_ROOT didn't help, but DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR set to ...\dotnet-sdk-8.0.204-win-x64 seems to have done the trick.

This is not a trivial knowledge, and some instructions should be included either at the SDK download page or in the zip archive. Thanks for help!

miloush avatar May 16 '24 14:05 miloush