diff --git a/src/MSBuildLocator/MSBuildLocator.cs b/src/MSBuildLocator/MSBuildLocator.cs index 7c7983d..7b3a582 100644 --- a/src/MSBuildLocator/MSBuildLocator.cs +++ b/src/MSBuildLocator/MSBuildLocator.cs @@ -139,17 +139,16 @@ public static void RegisterInstance(VisualStudioInstance instance) string nugetPath = Path.GetFullPath(Path.Combine(instance.MSBuildPath, "..", "..", "..", "Common7", "IDE", "CommonExtensions", "Microsoft", "NuGet")); if (Directory.Exists(nugetPath)) { - RegisterMSBuildPath(new string[] { instance.MSBuildPath, nugetPath }); + RegisterMSBuildPathsInternally(new string[] { instance.MSBuildPath, nugetPath }); } else { - RegisterMSBuildPath(instance.MSBuildPath); + RegisterMSBuildPathsInternally(new string[] { instance.MSBuildPath }); } } /// - /// Add assembly resolution for Microsoft.Build core dlls in the current AppDomain from the specified - /// path. + /// Add assembly resolution for Microsoft.Build core dlls in the current AppDomain from the specified path and register environment variables for it. /// /// /// Path to the directory containing a deployment of MSBuild binaries. @@ -160,12 +159,15 @@ public static void RegisterInstance(VisualStudioInstance instance) /// public static void RegisterMSBuildPath(string msbuildPath) { - RegisterMSBuildPath(new string[] { msbuildPath }); +#if NETCOREAPP + ApplyDotNetSdkEnvironmentVariables(msbuildPath); +#endif + RegisterMSBuildPathsInternally(new string[] { msbuildPath }); } /// /// Add assembly resolution for Microsoft.Build core dlls in the current AppDomain from the specified - /// path. + /// paths and register environment variables for the first path. /// /// /// Paths to directories containing a deployment of MSBuild binaries. @@ -176,6 +178,17 @@ public static void RegisterMSBuildPath(string msbuildPath) /// public static void RegisterMSBuildPath(string[] msbuildSearchPaths) { +#if NETCOREAPP + if (msbuildSearchPaths.Any()) + { + ApplyDotNetSdkEnvironmentVariables(msbuildSearchPaths.FirstOrDefault()); + } +#endif + RegisterMSBuildPathsInternally(msbuildSearchPaths); + } + + private static void RegisterMSBuildPathsInternally(string[] msbuildSearchPaths) + { if (msbuildSearchPaths.Length < 1) { throw new ArgumentException("Must provide at least one search path to RegisterMSBuildPath.");