@@ -10,15 +10,13 @@ internal static class MsBuildCommandExtensions
10
10
/// <summary>
11
11
/// Appends a call to msbuild.
12
12
/// </summary>
13
- /// <param name="cmdBuilder"></param>
14
- /// <param name="builder"></param>
15
13
/// <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 )
17
15
{
18
16
// mono doesn't ship with `msbuild` on Arm-based Macs, but we can fall back to
19
17
// msbuild that ships with `dotnet` which can be invoked with `dotnet msbuild`
20
18
// perhaps we should do this on all platforms?
21
- return builder . Actions . IsRunningOnAppleSilicon ( )
19
+ return builder . Actions . IsRunningOnAppleSilicon ( ) || preferDotnet
22
20
? cmdBuilder . RunCommand ( "dotnet" ) . Argument ( "msbuild" )
23
21
: cmdBuilder . RunCommand ( "msbuild" ) ;
24
22
}
@@ -75,13 +73,21 @@ BuildScript GetNugetRestoreScript() =>
75
73
QuoteArgument ( projectOrSolution . FullPath ) .
76
74
Argument ( "-DisableParallelProcessing" ) .
77
75
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
+
78
84
var nugetRestore = GetNugetRestoreScript ( ) ;
79
85
var msbuildRestoreCommand = new CommandBuilder ( builder . Actions ) .
80
- MsBuildCommand ( builder ) .
86
+ MsBuildCommand ( builder , preferDotnet ) .
81
87
Argument ( "/t:restore" ) .
82
88
QuoteArgument ( projectOrSolution . FullPath ) ;
83
89
84
- if ( builder . Actions . IsRunningOnAppleSilicon ( ) )
90
+ if ( builder . Actions . IsRunningOnAppleSilicon ( ) || preferDotnet )
85
91
{
86
92
// On Apple Silicon, only try package restore with `dotnet msbuild /t:restore`
87
93
ret &= BuildScript . Try ( msbuildRestoreCommand . Script ) ;
@@ -119,7 +125,7 @@ BuildScript GetNugetRestoreScript() =>
119
125
command . RunCommand ( "set Platform=&& type NUL" , quoteExe : false ) ;
120
126
}
121
127
122
- command . MsBuildCommand ( builder ) ;
128
+ command . MsBuildCommand ( builder , preferDotnet ) ;
123
129
command . QuoteArgument ( projectOrSolution . FullPath ) ;
124
130
125
131
var target = "rebuild" ;
0 commit comments