Skip to content

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

@jasonmalinowski

Description

@jasonmalinowski

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions