-
Notifications
You must be signed in to change notification settings - Fork 89
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:
- Add requested version to hostfxr_resolve_sdk2 dotnet/runtime#68355
- Add a flag to hostfxr_resolve_sdk2_flags_t to silence error messages dotnet/runtime#119729
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.