Skip to content

Commit

Permalink
add ApplyDotNetSdkEnvironmentVariables for custom MSBuild path(s) for…
Browse files Browse the repository at this point in the history
… .netcore env. (#283)
  • Loading branch information
YuliiaKovalova authored Mar 4, 2024
1 parent 482952e commit 604477e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="msbuildPath">
/// Path to the directory containing a deployment of MSBuild binaries.
Expand All @@ -160,12 +159,15 @@ public static void RegisterInstance(VisualStudioInstance instance)
/// </param>
public static void RegisterMSBuildPath(string msbuildPath)
{
RegisterMSBuildPath(new string[] { msbuildPath });
#if NETCOREAPP
ApplyDotNetSdkEnvironmentVariables(msbuildPath);
#endif
RegisterMSBuildPathsInternally(new string[] { msbuildPath });
}

/// <summary>
/// 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.
/// </summary>
/// <param name="msbuildSearchPaths">
/// Paths to directories containing a deployment of MSBuild binaries.
Expand All @@ -176,6 +178,17 @@ public static void RegisterMSBuildPath(string msbuildPath)
/// </param>
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.");
Expand Down

0 comments on commit 604477e

Please sign in to comment.