Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
KirillOsenkov opened this issue Sep 20, 2022 · 27 comments · Fixed by #10112 or #10118
Closed
Assignees
Labels
Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself.

Comments

@KirillOsenkov
Copy link
Member

KirillOsenkov commented Sep 20, 2022

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
Copy link
Member Author

Nothing seems to be logging anything into the SdkLogger.

This is never used for anything:

SdkLogger buildEngineLogger = new SdkLogger(loggingContext);

@KirillOsenkov
Copy link
Member Author

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
Copy link
Member Author

@marcpopMSFT

@KirillOsenkov
Copy link
Member Author

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

@KirillOsenkov
Copy link
Member Author

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.

@rainersigwald
Copy link
Member

Related to #6566, maybe

<!-- Disable workload resolver until we can figure out whether it can work in the bootstrap
https://github.com/dotnet/msbuild/issues/6566 -->
<Touch Files="$(BootstrapDestination)\DisableWorkloadResolver.sentinel" AlwaysCreate="true" />
should apply to netfx MSBuild too.

@KirillOsenkov
Copy link
Member Author

@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
Copy link
Member Author

I'll venmo $100 to whoever fixes this.

@ozkanpakdil
Copy link

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 ?

@miloush
Copy link

miloush commented May 4, 2024

@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.

@KirillOsenkov KirillOsenkov added the Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. label May 5, 2024
Forgind added a commit to Forgind/msbuild that referenced this issue May 6, 2024
If an SDK is a workload SDK, and we don't have the workload SDK resolver from the SDK, as, for instance, if we have an xcopy'd MSBuild, then we should still be able to build simple projects that don't require workloads. Right now, we just fail. If we get into a failure state, this tries to figure out if we actually need workloads, erring on the side of failing if we aren't sure. If we decide we don't need workloads, however, we suppress the error for failing to load a workload SDK.

Fixes dotnet#7988
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue May 6, 2024
This has been long done for .NET (core); extend it
to the location that the .NET Framework copy of
the SDK resolver looks for it too.

Fixes dotnet#7988.
@rainersigwald
Copy link
Member

rainersigwald commented May 6, 2024

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.

@miloush
Copy link

miloush commented May 6, 2024

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.

@rainersigwald
Copy link
Member

Using what MSBuild, @miloush?

@KirillOsenkov
Copy link
Member Author

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

@rainersigwald
Copy link
Member

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

@miloush
Copy link

miloush commented May 6, 2024

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

@rainersigwald
Copy link
Member

@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 rainersigwald self-assigned this May 6, 2024
@miloush
Copy link

miloush commented May 6, 2024

@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.

rainersigwald added a commit that referenced this issue May 7, 2024
This has been long done for .NET (core); extend it
to the location that the .NET Framework copy of
the SDK resolver looks for it too.

Closes #7988.
@KirillOsenkov KirillOsenkov reopened this May 7, 2024
@KirillOsenkov
Copy link
Member Author

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

@KirillOsenkov
Copy link
Member Author

Setting MSBuildEnableWorkloadResolver to false works as well.

@miloush
Copy link

miloush commented May 7, 2024

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
Copy link

miloush commented May 16, 2024

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.

@rainersigwald
Copy link
Member

@miloush don't set MSBuildSDKsPath; it doesn't do what you want. Instead set the .NET SDK resolver environment variables #7988 (comment).

@miloush
Copy link

miloush commented May 16, 2024

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!

@YuliiaKovalova
Copy link
Member

YuliiaKovalova commented Jul 30, 2024

It has to work after merging #10300

@YuliiaKovalova YuliiaKovalova self-assigned this Jul 30, 2024
@KirillOsenkov
Copy link
Member Author

"It has no work" - could you please clarify?

@YuliiaKovalova
Copy link
Member

"It has no work" - could you please clarify?

I apologize for the typo, it has TO work now :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself.
Projects
None yet
5 participants