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.23k stars 1.35k forks source link

Code to find MSBuild 15 toolset is not resilient to installations with errors #1939

Open KirillOsenkov opened 7 years ago

KirillOsenkov commented 7 years ago

On one machine my VS 2017 installation had errors (which is apparently not uncommon). On that machine hosting MSBuild 15 resulted in a lot of hard-to-diagnose problems. After some investigation I've narrowed it down to the codepath enumerating VS 2017 installations not returning any instances.

It turns out the code here is not tolerant against this case: http://source.dot.net/#Microsoft.Build/SharedUtilities/VisualStudioLocationHelper.cs,59

It checks for InstanceState.Complete, which is sometimes too restrictive. Here's the InstanceState enum:

namespace Microsoft.VisualStudio.Setup.Configuration
{
    [Flags]
    public enum InstanceState : uint
    {
        None = 0,
        Local = 1,
        Registered = 2,
        NoRebootRequired = 4,
        NoErrors = 8,
        Complete = uint.MaxValue
    }
}

The code in MSBuild only adds an instance if the state is Complete. However on the machine in question the state was Local | Registered | NoRebootRequired. Due to errors during setup the NoErrors flags was not set.

My understanding is that this check should include the instance if the state is anything but None or maybe ignore the State flag entirely.

jeffkl commented 7 years ago

Also raised here: https://github.com/Microsoft/msbuild/commit/68b96728bc2b7c554a37d12723e68e5d37768743#commitcomment-20959231

KirillOsenkov commented 7 years ago

Here's a simple tool I wrote to debug this: https://github.com/KirillOsenkov/VSInstanceFinder

And here's the official vswhere repo: https://github.com/Microsoft/VSWhere

jairbubbles commented 6 years ago

I've been hit by the same issue.

@KirillOsenkov Did you find a way to fix the install on the computer?

KirillOsenkov commented 6 years ago

Yes, I've launched the Visual Studio Installer and uninstalled or updated to make sure that all installed VS instances are healthy.

jairbubbles commented 6 years ago

Ok thx!

I guess having a detailed log would allow understanding what's going on. I've spent a lot of time figuring out what's happening as it was on someone else's computer 😭

The code the code is not trivial at all, there's a lot of differnt code paths for MsBuildPath detection (BuildEnvironmentHelper) but also for toolsets detection (ToolsetReader).