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

Improve Diagnosability of SDK Resolve Failure #6391

Open
msfcolombo opened this issue Apr 30, 2021 · 5 comments
Open

Improve Diagnosability of SDK Resolve Failure #6391

msfcolombo opened this issue Apr 30, 2021 · 5 comments
Labels
Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. triaged
Milestone

Comments

@msfcolombo
Copy link

When running msbuild, dotnet build or dotnet msbuild in the project below, I get the error:

C:\repo-path\sample\dirs.proj : error MSB4236: The SDK 'Microsoft.Build.Traversal' specified could not be found.

Here's the project:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Sdk="Microsoft.Build.Traversal">
  <ItemGroup>
     <ProjectFile Include="Sample\Sample.csproj" />
     <ProjectFile Include="SampleTest\SampleTest.csproj" />
  </ItemGroup>
</Project>

When running with -v diag, I've noticed that it does not attempt to install or restore the SDK.

I don't know how to install that SDK manually either. Documentation at https://github.com/microsoft/MSBuildSdks and https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk doesn't explain how to install. They just say that restore is automatic.

I also attempted -target:Restore but it says Target "Restore" skipped. The target does not exist in the project and SkipNonexistentTargets is set to true.

msbuild version

C:\repo-path\sample>"c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" --version
Microsoft (R) Build Engine version 16.9.0+5e4b48a27 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.9.0.16703

dotnet installed SDKs

C:\repo-path\sample>dotnet --list-sdks
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.523 [C:\Program Files\dotnet\sdk]
2.1.815 [C:\Program Files\dotnet\sdk]
2.2.110 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.103 [C:\Program Files\dotnet\sdk]
3.1.114 [C:\Program Files\dotnet\sdk]
5.0.202 [C:\Program Files\dotnet\sdk]

The problem happens when I select SDK 3.1.114 or 5.0.202. I confirm that in both cases it's searching the msbuild SDK on directory C:\Program Files\dotnet\sdk\{dotnet-SDK-version}\Sdks\Microsoft.Build.Traversal\Sdk, and it's not finding there because it does not exist.

I don't know how to install the msbuild SDK manually or what to do to fix the environment.

@msfcolombo msfcolombo added bug needs-triage Have yet to determine what bucket this goes in. labels Apr 30, 2021
msfcolombo referenced this issue in microsoft/MSBuildSdks Apr 30, 2021
@msfcolombo
Copy link
Author

I found the issue. Missing global.json file. Please improve the error message, or add more stuff to diagnostics verbosity. It tells absolutely nothing about search for global.json.

Thanks!

@jeffkl
Copy link
Contributor

jeffkl commented Apr 30, 2021

This will be improved due to #6312 which will fail the build at least

This documentation explains how to use MSBuild project SDKs: https://github.com/Microsoft/MSBuildSdks#how-can-i-use-these-sdks

This does as well: https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019#how-project-sdks-are-resolved

A NuGet-based resolver that queries your configured package feeds for NuGet packages that match the ID and version of the SDK you specified.

This resolver is only active if you specified an optional version. It can be used for any custom project SDK.

Its really hard to know that the reason that an SDK couldn't be resolved was because a version wasn't specified because each SDK resolver may or may not need a version.

@benvillalobos benvillalobos changed the title msbuild can't find and does not install Microsoft.Build.Traversal plugin/SDK Improve Diagnosability of SDK Resolve Failure May 5, 2021
@msfcolombo
Copy link
Author

Besides that, logs should tell that it attempted to open global.json to resolve the version, and could not find the file.

@rainersigwald
Copy link
Member

I feel like an aspect of the original design of SDK resolvers was lost here: each resolver can fail to find an SDK, and that's fine because there's a chain of them and the next one might. But if none of them do, we should emit the errors from each resolver, which would help pinpoint this.

I thought we had a preexisting bug for this but I can't find it now, so this is it.

@rainersigwald rainersigwald added Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. and removed bug needs-triage Have yet to determine what bucket this goes in. labels Jun 9, 2021
@rainersigwald rainersigwald added this to the 17.0 milestone Jun 9, 2021
@msfcolombo
Copy link
Author

Possibly related: dotnet/sdk#18048.

@marcpopMSFT marcpopMSFT modified the milestones: 17.0, MSBuild 17.1 Jul 9, 2021
@marcpopMSFT marcpopMSFT modified the milestones: VS 17.1, Backlog Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. triaged
Projects
None yet
Development

No branches or pull requests

5 participants