Skip to content

Commit 206642e

Browse files
[build] locate MSBuild properly (#43)
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.
1 parent b5140d6 commit 206642e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

build.cake

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ string sln = "./Xamarin.Forms.Mocks.sln";
1919
string version = "3.5.0.2";
2020
string suffix = "";
2121

22+
MSBuildSettings MSBuildSettings()
23+
{
24+
var settings = new MSBuildSettings { Configuration = configuration };
25+
26+
if (IsRunningOnWindows())
27+
{
28+
// Find MSBuild for Visual Studio 2019 and newer
29+
DirectoryPath vsLatest = VSWhereLatest();
30+
FilePath msBuildPath = vsLatest?.CombineWithFilePath("./MSBuild/Current/Bin/MSBuild.exe");
31+
32+
// Find MSBuild for Visual Studio 2017
33+
if (msBuildPath != null && !FileExists(msBuildPath))
34+
msBuildPath = vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/MSBuild.exe");
35+
36+
// Have we found MSBuild yet?
37+
if (!FileExists(msBuildPath))
38+
{
39+
throw new Exception($"Failed to find MSBuild: {msBuildPath}");
40+
}
41+
42+
Information("Building using MSBuild at " + msBuildPath);
43+
settings.ToolPath = msBuildPath;
44+
}
45+
else
46+
{
47+
settings.ToolPath = Context.Tools.Resolve("msbuild");
48+
}
49+
50+
return settings.WithRestore();
51+
}
52+
2253
Task("Clean")
2354
.Does(() =>
2455
{
@@ -30,7 +61,7 @@ Task("Build")
3061
.IsDependentOn("Clean")
3162
.Does(() =>
3263
{
33-
MSBuild(sln, settings => settings.SetConfiguration(configuration).WithRestore());
64+
MSBuild(sln, MSBuildSettings());
3465
});
3566

3667
Task("NUnit")

0 commit comments

Comments
 (0)