Skip to content

Commit

Permalink
fix: error extracting metadata when VSINSTALLDIR is set (dotnet#5204)
Browse files Browse the repository at this point in the history
  • Loading branch information
superyyrrzz authored Oct 17, 2019
1 parent fed2add commit 7010df7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.DocAsCode.Metadata.ManagedReference

public class MSBuildEnvironmentScope : IDisposable
{
private const string VSInstallDirKey = "VSINSTALLDIR";
private const string MSBuildExePathKey = "MSBUILD_EXE_PATH";
private readonly EnvironmentScope _innerScope;

Expand All @@ -25,13 +24,6 @@ public MSBuildEnvironmentScope()

private EnvironmentScope GetScope()
{
var vsInstallDirEnv = Environment.GetEnvironmentVariable(VSInstallDirKey);
if (!string.IsNullOrEmpty(vsInstallDirEnv))
{
Logger.LogInfo($"Environment variable {VSInstallDirKey} is set to {vsInstallDirEnv}, it is used as the inner compiler.");
return null;
}

var msbuildExePathEnv = Environment.GetEnvironmentVariable(MSBuildExePathKey);

if (!string.IsNullOrEmpty(msbuildExePathEnv))
Expand Down Expand Up @@ -80,7 +72,7 @@ private EnvironmentScope GetScope()
MSBuildLocator.RegisterInstance(latest);
return new EnvironmentScope(new Dictionary<string, string>
{
[VSInstallDirKey] = latest.VisualStudioRootPath,
["VSINSTALLDIR"] = latest.VisualStudioRootPath,
["VisualStudioVersion"] = latest.Version.ToString(2),
});
}
Expand Down
20 changes: 20 additions & 0 deletions test/docfx.Tests/MetadataCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Microsoft.DocAsCode.Tests
{
using System;
using System.Collections.Generic;
using System.IO;

Expand Down Expand Up @@ -48,6 +49,25 @@ public void TestMetadataCommandFromCSProject()
CheckResult();
}

[Fact]
[Trait("Related", "docfx")]
[Trait("Language", "CSharp")]
public void TestMetadataCommandFromCSProjectWithVsinstalldirEnvSet()
{
var envName = "VSINSTALLDIR";
var originalValue = Environment.GetEnvironmentVariable(envName);
Environment.SetEnvironmentVariable(envName, "c:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise");

try
{
TestMetadataCommandFromCSProject();
}
finally
{
Environment.SetEnvironmentVariable(envName, originalValue);
}
}

[Fact]
[Trait("Related", "docfx")]
[Trait("Language", "CSharp")]
Expand Down

0 comments on commit 7010df7

Please sign in to comment.