Throw a graceful exception if the SDK needed by a project is not installed

Open
#337 3 comments 2 reactions 1 assignee View on GitHub

@YuliiaKovalova is already working on this.

Since Sep 29, 2025.

Assessment

This issue has not been assessed yet.

Description

Right now if you use MSBuildLocator to locate an MSBuild for an SDK-style project, and the SDK is not installed, you get a particularly unfriendly error mode. An exception is thrown that says "An exception of type System.InvalidOperationException was thrown: Failed to find all versions of .NET Core MSBuild. Call to hostfxr_resolve_sdk2. There may be more details in stderr.". In some cases (like the C# extension) stderr was written out to a child process, so unless you go digging in a bunch of trace logs, you won't see the real cause of the problem.

Chatting with the SDK team, hostfxr_resolve_sdk2 has been given some new APIs to help us deal with this case:

With this we can know the requested version and global.json, so we could instead throw a smart exception that says the SDK specified in the global.json could not be found. If we threw a more concrete exception type (like an SdkNotFoundException) we could also give a nice message to the user in that case. I'd say a generic InvalidOperationException might still be appropriate if the underlying failure isn't understood.

It's possible #331 is a duplicate of this issue as well; that's the same symptoms but the described scenario is a bit different, but maybe improvements here help that too.

Dominant language
C#
Stars
262
Forks
91
Avg merge
11d 22h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/MSBuildLocator

All issues in microsoft/MSBuildLocator

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.