When the VSINSTALLDIR environment variable is set even though the tool is not running from a Developer command prompt, QueryVisualStudioInstances() fails with a NullReferenceException.
Stacktrace:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Build.Locator.VisualStudioInstance..ctor(String name, String path, Version version, DiscoveryType discoveryType)
at Microsoft.Build.Locator.MSBuildLocator.GetDevConsoleInstance()
at Microsoft.Build.Locator.MSBuildLocator.<GetInstances>d__20.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
Looking at the code, I guess there is a version != null check missing in GetDevConsoleInstance
This also happens when DiscoveryTypes is set to DiscoveryType.VisualStudioSetup only