Reputation: 3331
I would like to use MSBuildLocator within a .NET Core app to build a .NET Framework app.
The issue is, on a system with both VS2019 and VS2022 installed, running:
var instances = MSBuildLocator.QueryVisualStudioInstances().ToList();
from inside a .NET 6.0 application returns:
C:\Program Files\dotnet\sdk\6.0.321
C:\Program Files\dotnet\sdk\6.0.203
C:\Program Files\dotnet\sdk\5.0.416
C:\Program Files\dotnet\sdk\5.0.408
C:\Program Files\dotnet\sdk\3.1.426
and from a .NET 4.8 application returns:
C:\Development Tools\Environments\Microsoft\Visual Studio\2022\MSBuild\Current\Bin
C:\Development Tools\Environments\Microsoft\Visual Studio\2019\MSBuild\Current\Bin
I can't seem to find a way to get MSBuildLocator to give me all the MSBuild locations, (or at least give me the latter two) from within a .NET Core application.
Upvotes: 0
Views: 54
Reputation: 3331
After digging through the Microsoft.Build.Locator code, it was clear that, yes, it does indeed do one lookup or the other based on the current framework type (core vs full), basically the package will copy over a net6.0 or a net46 assembly depending on project type it's added do.
Internally the Microsoft.Build.Locator uses the Microsoft.VisualStudio.Setup.Configuration.Interop package to query the locations of any VS or VS Build Tools installations (when targeting a full framework) in order to determine the underlying MSBuild.exe paths.
So in order to query both core and full framework MSBuild locations (from a .NET core application), it's presently necessary extract some code, and create a second helper routine to work along-side Microsoft.Build.Locator. Perhaps this will change in the future, I see no reason why it couldn't just return all the options in either case.
Upvotes: 0