Closed louis-z closed 3 years ago
Hi @louis-z,
Can you clarify what the undesirable behavior you're seeing is? The code you pasted at the bottom is almost identical to what MSBuildLocator.RegisterDefaults() does—the only differences being that you sorted the instances it found before returning the first one, and your version filters out instances with the wrong discovery type.
Can you clarify what the undesirable behavior you're seeing is? The code you pasted at the bottom is almost identical to what MSBuildLocator.RegisterDefaults() does—the only differences being that you sorted the instances it found before returning the first one, and your version filters out instances with the wrong discovery type.
I have this setup where
are installed. From that setup, I would expect MSBuildLocator.RegisterDefaults() to select the highest version of MSBuild available, thus the one that comes with the VS2019 build tools. Unfortunately, it seems to pick instead the highest MSBuild version from full IDE installations.
BTW I'm using Microsoft.Build.Locator version 1.2.6.
RegisterDefaults doesn't work very hard to choose the best version, partially because what "the best" version is varies per user experience. As an example, you would like the newest version, which makes sense, but someone else could want the oldest version because it's probably the most stable, or the newest version that came with a full VS install, or...
You can see there are a lot of possible ways it could determine which is best. I'd recommend using RegisterInstance, as you suggested, since it lets you specify which you want.
Sounds good. Closing the issue.
MSBuildLocator.RegisterDefaults()
does not use MSBuild.exe's location when only the build tools are installed, not the whole IDE.Does it use the same logic as this
vswhere
command?I believe it should instead behave as the following command:
Note that replacing
MSBuildLocator.RegisterDefaults()
with something like the following ends up yielding the desired behavior: