提交 9f8c179c 编写于 作者: K Kevin Pilch-Bisson

Extract common code to a helper method

上级 7cef3b45
......@@ -16,8 +16,6 @@
using System.Xml;
using System.Threading.Tasks;
using static System.FormattableString;
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
{
public class IntegrationTests : TestBase
......@@ -27,19 +25,8 @@ public class IntegrationTests : TestBase
static IntegrationTests()
{
var vsVersion = Environment.GetEnvironmentVariable("VisualStudioVersion") ?? "14.0";
using (var key = Registry.LocalMachine.OpenSubKey(Invariant($@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\{vsVersion}"), writable: false))
{
if (key != null)
{
var toolsPath = key.GetValue("MSBuildToolsPath");
if (toolsPath != null)
{
s_msbuildDirectory = toolsPath.ToString();
s_msbuildExecutable = Path.Combine(s_msbuildDirectory, "MSBuild.exe");
}
}
}
s_msbuildDirectory = TestHelpers.GetMSBuildDirectory();
s_msbuildExecutable = Path.Combine(s_msbuildDirectory, "MSBuild.exe");
}
private readonly TempDirectory _tempDirectory;
......
......@@ -22,8 +22,6 @@
using Microsoft.CodeAnalysis.CommandLine;
using Moq;
using static System.FormattableString;
namespace Microsoft.CodeAnalysis.CompilerServer.UnitTests
{
public class CompilerServerUnitTests : TestBase
......@@ -53,7 +51,7 @@ static CompilerServerUnitTests()
// VBCSCompiler is used as a DLL in these tests, need to hook the resolve to the installed location.
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
basePath = GetMSBuildDirectory();
basePath = TestHelpers.GetMSBuildDirectory();
if (basePath == null)
{
return;
......@@ -76,24 +74,6 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs e)
return null;
}
private static string GetMSBuildDirectory()
{
var vsVersion = Environment.GetEnvironmentVariable("VisualStudioVersion") ?? "14.0";
using (var key = Registry.LocalMachine.OpenSubKey(Invariant($@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\{vsVersion}"), false))
{
if (key != null)
{
var toolsPath = key.GetValue("MSBuildToolsPath");
if (toolsPath != null)
{
return toolsPath.ToString();
}
}
}
return null;
}
private static readonly KeyValuePair<string, string>[] s_helloWorldSrcCs =
{
new KeyValuePair<string, string>("hello.cs",
......
......@@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.Win32;
namespace Roslyn.Test.Utilities
{
......@@ -145,5 +146,24 @@ public static string AsXmlCommentText(string text)
Debug.Assert(!result.Contains("--"));
return result;
}
public static string GetMSBuildDirectory()
{
var vsVersion = Environment.GetEnvironmentVariable("VisualStudioVersion") ?? "14.0";
using (var key = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\{vsVersion}", false))
{
if (key != null)
{
var toolsPath = key.GetValue("MSBuildToolsPath");
if (toolsPath != null)
{
return toolsPath.ToString();
}
}
}
return null;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册