Skip to content

Commit

Permalink
[build] locate MSBuild properly (#43)
Browse files Browse the repository at this point in the history
Context: nunit/nunit#3194

I tried to build this repo on a new machine that only has VS 2019 installed. It didn't build...

I pulled a fix over that NUnit is using in their Cake script.
  • Loading branch information
jonathanpeppers authored Jun 21, 2019
1 parent b5140d6 commit 206642e
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@ string sln = "./Xamarin.Forms.Mocks.sln";
string version = "3.5.0.2";
string suffix = "";

MSBuildSettings MSBuildSettings()
{
var settings = new MSBuildSettings { Configuration = configuration };

if (IsRunningOnWindows())
{
// Find MSBuild for Visual Studio 2019 and newer
DirectoryPath vsLatest = VSWhereLatest();
FilePath msBuildPath = vsLatest?.CombineWithFilePath("./MSBuild/Current/Bin/MSBuild.exe");

// Find MSBuild for Visual Studio 2017
if (msBuildPath != null && !FileExists(msBuildPath))
msBuildPath = vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/MSBuild.exe");

// Have we found MSBuild yet?
if (!FileExists(msBuildPath))
{
throw new Exception($"Failed to find MSBuild: {msBuildPath}");
}

Information("Building using MSBuild at " + msBuildPath);
settings.ToolPath = msBuildPath;
}
else
{
settings.ToolPath = Context.Tools.Resolve("msbuild");
}

return settings.WithRestore();
}

Task("Clean")
.Does(() =>
{
Expand All @@ -30,7 +61,7 @@ Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
MSBuild(sln, settings => settings.SetConfiguration(configuration).WithRestore());
MSBuild(sln, MSBuildSettings());
});

Task("NUnit")
Expand Down

0 comments on commit 206642e

Please sign in to comment.