@@ -10,15 +10,15 @@ 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+ // Similarly, there's no point in trying to rely on mono if it's not installed.
20+ // In which case we can still fall back to `dotnet msbuild`.
21+ return preferDotnet
2222 ? cmdBuilder . RunCommand ( "dotnet" ) . Argument ( "msbuild" )
2323 : cmdBuilder . RunCommand ( "msbuild" ) ;
2424 }
@@ -75,13 +75,16 @@ BuildScript GetNugetRestoreScript() =>
7575 QuoteArgument ( projectOrSolution . FullPath ) .
7676 Argument ( "-DisableParallelProcessing" ) .
7777 Script ;
78+
79+ var preferDotnet = builder . Actions . IsRunningOnAppleSilicon ( ) || ! builder . Actions . IsWindows ( ) && ! builder . Actions . IsMonoInstalled ( ) ;
80+
7881 var nugetRestore = GetNugetRestoreScript ( ) ;
7982 var msbuildRestoreCommand = new CommandBuilder ( builder . Actions ) .
80- MsBuildCommand ( builder ) .
83+ MsBuildCommand ( builder , preferDotnet ) .
8184 Argument ( "/t:restore" ) .
8285 QuoteArgument ( projectOrSolution . FullPath ) ;
8386
84- if ( builder . Actions . IsRunningOnAppleSilicon ( ) )
87+ if ( preferDotnet )
8588 {
8689 // On Apple Silicon, only try package restore with `dotnet msbuild /t:restore`
8790 ret &= BuildScript . Try ( msbuildRestoreCommand . Script ) ;
@@ -119,7 +122,7 @@ BuildScript GetNugetRestoreScript() =>
119122 command . RunCommand ( "set Platform=&& type NUL" , quoteExe : false ) ;
120123 }
121124
122- command . MsBuildCommand ( builder ) ;
125+ command . MsBuildCommand ( builder , preferDotnet ) ;
123126 command . QuoteArgument ( projectOrSolution . FullPath ) ;
124127
125128 var target = "rebuild" ;
0 commit comments