dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.17k stars 1.34k forks source link

"ToolLocationHelper.GetPathToBuildToolsFile" returns null if running under net core 2.1 #4013

Open ramoneeza opened 5 years ago

ramoneeza commented 5 years ago

Steps to reproduce

1) Create a new dotnet console app in Visual Studio 2) Add nuget package Microsoft.Build.Utilities.Core 3) Try to find where msbuild 15.x is located:

var path=ToolLocationHelper.GetPathToBuildToolsFile("msbuild.exe", buildversion);

Result is NULL under NetCore

3) Create a new .NET 4.7.1 console app in Visual Studio 4) Add nuget package Microsoft.Build.Utilities.Core 5) Repeat under .net frameword 4.7.1 the search again:

var path=ToolLocationHelper.GetPathToBuildToolsFile("msbuild.exe", buildversion);

Result is MSBUILD PATH under Visual Studio 2017 as expected.


Since ToolLocationHelper can be used via Nuget in both circunstances... I think there is a problem with dotnet, not been able to obtain msbuild location.

livarcocc commented 5 years ago

I wonder if this is because in the .net core case, you should say msbuild.dll instead of msbuild.exe.

ramoneeza commented 5 years ago

No. "msbuild.dll" doesn't work. Simply it returns allways null

cveld commented 5 years ago

When running in a .NET Core 2.1 context, what is the preferred way to get the ToolsPath for legacy csproj projects? Ref https://github.com/RSuter/DNT/issues/31

rainersigwald commented 5 years ago

@cveld Building or loading legacy projects is not supported in .NET Core MSBuild.

rainersigwald commented 5 years ago

Likewise, we don't anticipate supporting using a .NET Core version of ToolLocationHelper to find full-framework MSBuild. https://github.com/Microsoft/MSBuildLocator can be used to find MSBuild in a Visual Studio installation, but only from a full-framework application.