From 9801c6d9e76dfc5721f5143e2e051c95fcd20a2b Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Wed, 30 Nov 2016 08:24:54 -0600 Subject: [PATCH] Default MSBuildSDKsPath location to {tools}\Sdks --- src/Shared/BuildEnvironmentHelper.cs | 13 +++++++++++++ src/Shared/Constants.cs | 5 +++++ .../Definition/ToolsetLocalReader.cs | 1 + .../Evaluation/IntrinsicFunctions.cs | 5 +++++ src/XMakeBuildEngine/Evaluation/ProjectParser.cs | 6 ++---- src/XMakeCommandLine/app.amd64.config | 1 + src/XMakeCommandLine/app.config | 1 + 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Shared/BuildEnvironmentHelper.cs b/src/Shared/BuildEnvironmentHelper.cs index 97447eb2e94..374f897424a 100644 --- a/src/Shared/BuildEnvironmentHelper.cs +++ b/src/Shared/BuildEnvironmentHelper.cs @@ -443,6 +443,19 @@ public BuildEnvironment(string processNameCommandLine, bool runningTests, bool r /// internal string MSBuildToolsDirectory64 { get; private set; } + /// + /// Path to the Sdks folder for this MSBuild instance. + /// + internal string MSBuildSDKsPath + { + get + { + // Allow an environment-variable override of the default SDK location + return Environment.GetEnvironmentVariable("MSBuildSDKsPath") ?? + Path.Combine(CurrentMSBuildToolsDirectory, "Sdks"); + } + } + /// /// Full path to the current MSBuild configuration file. /// diff --git a/src/Shared/Constants.cs b/src/Shared/Constants.cs index 99d7a4ffded..17670cc9903 100644 --- a/src/Shared/Constants.cs +++ b/src/Shared/Constants.cs @@ -21,6 +21,11 @@ internal static class MSBuildConstants /// internal const string ToolsPath64 = "MSBuildToolsPath64"; + /// + /// Name of the property that indicates the root of the SDKs folder + /// + internal const string SdksPath = "MSBuildSDKsPath"; + /// /// The most current Visual Studio Version known to this version of MSBuild. /// diff --git a/src/XMakeBuildEngine/Definition/ToolsetLocalReader.cs b/src/XMakeBuildEngine/Definition/ToolsetLocalReader.cs index 7b83083536f..ea0961b9a22 100644 --- a/src/XMakeBuildEngine/Definition/ToolsetLocalReader.cs +++ b/src/XMakeBuildEngine/Definition/ToolsetLocalReader.cs @@ -57,6 +57,7 @@ protected override IEnumerable ToolsVersions protected override IEnumerable GetPropertyDefinitions(string toolsVersion) { yield return new ToolsetPropertyDefinition(MSBuildConstants.ToolsPath, BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, _sourceLocation); + yield return new ToolsetPropertyDefinition(MSBuildConstants.SdksPath, BuildEnvironmentHelper.Instance.MSBuildSDKsPath, _sourceLocation); yield return new ToolsetPropertyDefinition("RoslynTargetsPath", BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, _sourceLocation); } diff --git a/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs b/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs index 5c059fc008d..2952b978120 100644 --- a/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs +++ b/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs @@ -390,6 +390,11 @@ public static string GetToolsDirectory64() return BuildEnvironmentHelper.Instance.MSBuildToolsDirectory64; } + public static string GetMSBuildSDKsPath() + { + return BuildEnvironmentHelper.Instance.MSBuildSDKsPath; + } + public static string GetVsInstallRoot() { return BuildEnvironmentHelper.Instance.VisualStudioInstallRootDirectory; diff --git a/src/XMakeBuildEngine/Evaluation/ProjectParser.cs b/src/XMakeBuildEngine/Evaluation/ProjectParser.cs index dbf0ff10d7b..b6c56acf353 100644 --- a/src/XMakeBuildEngine/Evaluation/ProjectParser.cs +++ b/src/XMakeBuildEngine/Evaluation/ProjectParser.cs @@ -189,8 +189,6 @@ private void ParseProjectElement(XmlElementWithLocation element) if (element.HasAttribute(XMakeAttributes.sdk)) { - // TODO: don't get root of SDKs from the environment, use a built-in or toolset prop - // TODO: Don't null ref if MSBuildSDKsPath isn't defined var sdksString = element.GetAttribute(XMakeAttributes.sdk); @@ -210,9 +208,9 @@ private void ParseProjectElement(XmlElementWithLocation element) } // TODO: paths should just be Sdk.props/targets; Sdk-aware imports should do the rest of the path. - var initialImportPath = Path.Combine(Environment.GetEnvironmentVariable("MSBuildSDKsPath"), + var initialImportPath = Path.Combine(BuildEnvironmentHelper.Instance.MSBuildSDKsPath, sdkName, "Sdk", "Sdk.props"); - var finalImportPath = Path.Combine(Environment.GetEnvironmentVariable("MSBuildSDKsPath"), + var finalImportPath = Path.Combine(BuildEnvironmentHelper.Instance.MSBuildSDKsPath, sdkName, "Sdk", "Sdk.targets"); if (File.Exists(initialImportPath)) diff --git a/src/XMakeCommandLine/app.amd64.config b/src/XMakeCommandLine/app.amd64.config index 28e02901c72..580d15eb1fd 100644 --- a/src/XMakeCommandLine/app.amd64.config +++ b/src/XMakeCommandLine/app.amd64.config @@ -60,6 +60,7 @@ + diff --git a/src/XMakeCommandLine/app.config b/src/XMakeCommandLine/app.config index b5962352ead..5dbaca1e18e 100644 --- a/src/XMakeCommandLine/app.config +++ b/src/XMakeCommandLine/app.config @@ -54,6 +54,7 @@ +