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

[tests] fixed search paths for MSBuild on Windows #869

Merged
merged 1 commit into from
Sep 18, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class Builder : IDisposable
const string fixed_linux_xbuild_path = "/usr/bin";
const string xbuildapp = "xbuild";
const string msbuildapp = "msbuild";
string msbuildExe;

public bool IsUnix { get; set; }
public bool RunningMSBuild { get; set; }
Expand All @@ -36,11 +35,57 @@ string GetUnixBuildExe ()
return File.Exists (path) ? path : msbuildapp;
}

string GetVisualStudio2017Directory ()
{
var editions = new [] {
"Enterprise",
"Professional",
"Community",
"BuildTools"
};

var x86 = Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86);
foreach (var edition in editions) {
var dir = Path.Combine (x86, "Microsoft Visual Studio", "2017", edition);
if (Directory.Exists (dir))
return dir;
}

return null;
}

string GetWindowsBuildExe ()
{
RunningMSBuild = true;

//First try environment variable
string msbuildExe = Environment.GetEnvironmentVariable ("XA_MSBUILD_EXE");
if (!string.IsNullOrEmpty (msbuildExe) && File.Exists (msbuildExe))
return msbuildExe;

//Next try VS 2017, MSBuild 15.0
var visualStudioDirectory = GetVisualStudio2017Directory ();
if (!string.IsNullOrEmpty(visualStudioDirectory)) {
msbuildExe = Path.Combine (visualStudioDirectory, "MSBuild", "15.0", "Bin", "MSBuild.exe");

if (File.Exists (msbuildExe))
return msbuildExe;
}

//Try older than VS 2017, MSBuild 14.0
msbuildExe = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86), "MSBuild", "14.0", "Bin", "MSBuild.exe");
if (File.Exists (msbuildExe))
return msbuildExe;

//MSBuild 4.0 last resort
return Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Windows), "Microsoft.NET", "Framework", "v4.0.30319", "MSBuild.exe");
}

public string MSBuildExe {
get {
return IsUnix
? GetUnixBuildExe ()
: msbuildExe;
: GetWindowsBuildExe ();
}
}

Expand All @@ -59,6 +104,10 @@ public string FrameworkLibDirectory {
return Path.Combine (outdir, "lib", "xamarin.android");
}
else {
var visualStudioDirectory = GetVisualStudio2017Directory ();
if (!string.IsNullOrEmpty (visualStudioDirectory))
return Path.Combine (visualStudioDirectory, "MSBuild", "Xamarin", "Android");

var x86 = Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86);
return Path.Combine (x86, "MSBuild", "Xamarin", "Android");
}
Expand Down Expand Up @@ -113,13 +162,6 @@ public Builder ()
{
IsUnix = Environment.OSVersion.Platform != PlatformID.Win32NT;
BuildLogFile = "build.log";
// Allow the override of the location of MSBuild and try a couple of backup paths for
// MSBuild 14.0 and 4.0
msbuildExe = Environment.GetEnvironmentVariable ("XA_MSBUILD_EXE");
if (String.IsNullOrEmpty (msbuildExe) || !File.Exists (msbuildExe))
msbuildExe = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86), "MSBuild", "14.0", "Bin", "MSBuild.exe");
if (!File.Exists (msbuildExe))
msbuildExe = string.Format ("{0}\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe", Environment.GetEnvironmentVariable ("WINDIR"));
}

public void Dispose ()
Expand Down