Skip to content

Commit 40776c2

Browse files
committed
WIP: Do not try running mono when it's not available on the runner
1 parent 159d31d commit 40776c2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Diff for: csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs

+13-7
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ internal static class MsBuildCommandExtensions
1010
/// <summary>
1111
/// Appends a call to msbuild.
1212
/// </summary>
13-
/// <param name="cmdBuilder"></param>
14-
/// <param name="builder"></param>
1513
/// <returns></returns>
16-
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder)
14+
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder, bool preferDotnet)
1715
{
1816
// mono doesn't ship with `msbuild` on Arm-based Macs, but we can fall back to
1917
// msbuild that ships with `dotnet` which can be invoked with `dotnet msbuild`
2018
// perhaps we should do this on all platforms?
21-
return builder.Actions.IsRunningOnAppleSilicon()
19+
return builder.Actions.IsRunningOnAppleSilicon() || preferDotnet
2220
? cmdBuilder.RunCommand("dotnet").Argument("msbuild")
2321
: cmdBuilder.RunCommand("msbuild");
2422
}
@@ -75,13 +73,21 @@ BuildScript GetNugetRestoreScript() =>
7573
QuoteArgument(projectOrSolution.FullPath).
7674
Argument("-DisableParallelProcessing").
7775
Script;
76+
77+
BuildScript GetMonoVersionScript() => new CommandBuilder(builder.Actions).
78+
RunCommand("mono").
79+
Argument("--version").
80+
Script;
81+
82+
var preferDotnet = !builder.Actions.IsWindows() && GetMonoVersionScript().Run(builder.Actions, (_, _) => { }, (_, _, _) => { }) != 0;
83+
7884
var nugetRestore = GetNugetRestoreScript();
7985
var msbuildRestoreCommand = new CommandBuilder(builder.Actions).
80-
MsBuildCommand(builder).
86+
MsBuildCommand(builder, preferDotnet).
8187
Argument("/t:restore").
8288
QuoteArgument(projectOrSolution.FullPath);
8389

84-
if (builder.Actions.IsRunningOnAppleSilicon())
90+
if (builder.Actions.IsRunningOnAppleSilicon() || preferDotnet)
8591
{
8692
// On Apple Silicon, only try package restore with `dotnet msbuild /t:restore`
8793
ret &= BuildScript.Try(msbuildRestoreCommand.Script);
@@ -119,7 +125,7 @@ BuildScript GetNugetRestoreScript() =>
119125
command.RunCommand("set Platform=&& type NUL", quoteExe: false);
120126
}
121127

122-
command.MsBuildCommand(builder);
128+
command.MsBuildCommand(builder, preferDotnet);
123129
command.QuoteArgument(projectOrSolution.FullPath);
124130

125131
var target = "rebuild";

0 commit comments

Comments
 (0)