microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
218 stars 83 forks source link

QueryVisualStudioInstances() fails with NullReferenceException when VSINSTALLDIR is set #65

Closed ap0llo closed 5 years ago

ap0llo commented 5 years ago

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