Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApplyDotNetSdkEnvironmentVariables for custom MSBuild path(s) #283

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading