microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
216 stars 83 forks source link

Migrate .NET (Core) discovery to hosting layer APIs #111

Closed rainersigwald closed 2 years ago

rainersigwald commented 3 years ago

Currently we enumerate .NET SDK instances by spawning dotnet --info and parsing the textual output. But that's inefficient and it turns out there are APIs designed for almost exactly the situations we have, including global.json handling:

https://github.com/dotnet/runtime/blob/6072e4d3a7a2a1493f514cdf4be75a3d56580e84/docs/design/features/hosting-layer-apis.md

Specifically, Locator should call hostfxr_resolve_sdk2 to get the highest-priority/default SDK, and hostfxr_get_available_sdks to populate the full list.

rainersigwald commented 2 years ago

This should fix https://github.com/dotnet/msbuild/issues/7466 in addition to being faster.