Skip to content

MSBuildLocator does not locate MSBuild #197

@BittermanAndy

Description

@BittermanAndy

The readme.md for this project, and all supporting documentation elsewhere, claims that MSBuildLocator "ensures that your application gets the same view of projects as MSBuild.exe, dotnet build, or Visual Studio", because "additional build logic is distributed with Visual Studio, with Visual Studio extensions, or as part of the .NET SDK. So to correctly load projects, you need to load them in the context of one of those MSBuild installations."

All of this is a lie.

MSBuildLocator DOES NOT locate MSBuild. MSBuildLocator ONLY locates the dotnet SDK. This means that after using MSBuildLocator.RegisterDefaults() or any variation thereof, the Microsoft.Build assemblies that are loaded will be from the dotnet SDK folder, not the Visual Studio folder, and it will know nothing about any Visual Studio extensions, such as VSIX or the Installer Projects, and nor will it set any Visual Studio-related environment variables, such as $(VSToolsPath), used by such extensions. This means attempting to build such projects will result in build failures.

It is possible to manually find or specify an appropriate Visual Studio folder, and load the Microsoft.Build assemblies from that using something like MSBuildLocator.RegisterMSBuildPath("C:\\Program Files\\Microsoft Visual Studio\\2022\\Community"). Of course, this means MSBuildLocator isn't actually doing anything at that point. Furthermore, while I can then use the loaded Microsoft.Build libraries to interact with types such as SolutionFile, when I try to build a project using BuildManager (in the same way that works when using the other approach), the build appears to start OK then immediately crashes loading a type from mscorlib.dll. I don't even know where to start with fixing that.

Please fix MSBuildLocator such that it actually locates MSBuild, and actually does what it claims to do. Building in Visual Studio works fine, running msbuild from the command line works fine, my automated builds work fine in DevOps; but I'm trying to build things programmatically using MSBuildLocator and the Microsoft.Build assemblies, and all they need to do is whatever msbuild from the command line does, but it simply doesn't work, with the documentation lying about it.

Metadata

Metadata

Assignees

No one assigned

    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