From 709b69aaf2df8d4b99bb0eb3a560e62d3b09ceb5 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 6 Nov 2017 17:27:04 -0500 Subject: [PATCH] [xabuild.exe] fix for .NET standard projects Context: https://github.com/Microsoft/msbuild/blob/master/src/Shared/BuildEnvironmentHelper.cs#L511 `xabuild.exe` did not support building .NET standard projects. It turns out a `MSBuildSDKPaths` environment variable needed to be set for locating the `Sdks` directory. On Windows, this path is relative to Visual Studio / MSBuild, but on Mac I had to hardcode the path to .NET Core. It seems to use the same path on Linux as well. --- tools/xabuild/XABuild.cs | 1 + tools/xabuild/XABuildPaths.cs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/tools/xabuild/XABuild.cs b/tools/xabuild/XABuild.cs index 04f9692bca0..1ff4d134941 100644 --- a/tools/xabuild/XABuild.cs +++ b/tools/xabuild/XABuild.cs @@ -103,6 +103,7 @@ static XmlDocument CreateConfig (XABuildPaths paths) xml.Save (paths.XABuildConfig); + Environment.SetEnvironmentVariable ("MSBuildSDKsPath", paths.MSBuildSdksPath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable ("MSBUILD_EXE_PATH", paths.MSBuildExeTempPath, EnvironmentVariableTarget.Process); return xml; } diff --git a/tools/xabuild/XABuildPaths.cs b/tools/xabuild/XABuildPaths.cs index 9d8565dded9..469eb65e59e 100644 --- a/tools/xabuild/XABuildPaths.cs +++ b/tools/xabuild/XABuildPaths.cs @@ -66,6 +66,11 @@ class XABuildPaths /// public string MSBuildExtensionsPath { get; private set; } + /// + /// Used as the MSBuildSDKsPath environment variable, required for .NET standard projects to build + /// + public string MSBuildSdksPath { get; private set; } + /// /// Array of search paths for MSBuildExtensionsPath /// @@ -113,6 +118,7 @@ public XABuildPaths () MSBuildPath = Path.Combine (VsInstallRoot, "MSBuild"); MSBuildBin = Path.Combine (MSBuildPath, "15.0", "Bin"); MSBuildConfig = Path.Combine (MSBuildBin, "MSBuild.exe.config"); + MSBuildSdksPath = Path.Combine (MSBuildPath, "Sdks"); ProjectImportSearchPaths = new [] { MSBuildPath, "$(MSBuildProgramFiles32)\\MSBuild" }; SystemProfiles = Path.Combine (programFiles, "Reference Assemblies", "Microsoft", "Framework"); SearchPathsOS = "windows"; @@ -122,6 +128,7 @@ public XABuildPaths () MSBuildPath = Path.Combine (mono, "msbuild"); MSBuildBin = Path.Combine (MSBuildPath, "15.0", "bin"); MSBuildConfig = Path.Combine (MSBuildBin, "MSBuild.dll.config"); + MSBuildSdksPath = "/usr/local/share/dotnet/sdk/2.0.0/Sdks"; ProjectImportSearchPaths = new [] { MSBuildPath, Path.Combine (mono, "xbuild"), Path.Combine (monoExternal, "xbuild") }; SystemProfiles = Path.Combine (mono, "xbuild-frameworks"); SearchPathsOS = IsMacOS ? "osx" : "unix";