11using System ;
22using System . Collections . Generic ;
3+ using System . Collections . ObjectModel ;
34using System . IO ;
45using System . Linq ;
56using Newtonsoft . Json . Linq ;
@@ -140,6 +141,8 @@ public IList<string> GetNugetFeedsFromFolder(string folderPath)
140141 // The version number should be kept in sync with the version .NET version used for building the application.
141142 public const string LatestDotNetSdkVersion = "9.0.300" ;
142143
144+ public static ReadOnlyDictionary < string , string > MinimalEnvironment => IDotNetCliInvoker . MinimalEnvironment ;
145+
143146 /// <summary>
144147 /// Returns a script for downloading relevant versions of the
145148 /// .NET SDK. The SDK(s) will be installed at <code>installDir</code>
@@ -254,7 +257,6 @@ BuildScript GetInstall(string pwsh) =>
254257 else
255258 {
256259 var dotnetInstallPath = actions . PathCombine ( tempWorkingDirectory , ".dotnet" , "dotnet-install.sh" ) ;
257-
258260 var downloadDotNetInstallSh = BuildScript . DownloadFile (
259261 "https://dot.net/v1/dotnet-install.sh" ,
260262 dotnetInstallPath ,
@@ -269,17 +271,28 @@ BuildScript GetInstall(string pwsh) =>
269271 prelude = downloadDotNetInstallSh & chmod . Script ;
270272 postlude = shouldCleanUp ? BuildScript . DeleteFile ( dotnetInstallPath ) : BuildScript . Success ;
271273
272- getInstall = version => new CommandBuilder ( actions ) .
273- RunCommand ( dotnetInstallPath ) .
274- Argument ( "--channel" ) .
275- Argument ( "release" ) .
276- Argument ( "--version" ) .
277- Argument ( version ) .
278- Argument ( "--install-dir" ) .
279- Argument ( path ) . Script ;
274+ getInstall = version =>
275+ {
276+ var cb = new CommandBuilder ( actions ) .
277+ RunCommand ( dotnetInstallPath ) .
278+ Argument ( "--channel" ) .
279+ Argument ( "release" ) .
280+ Argument ( "--version" ) .
281+ Argument ( version ) ;
282+
283+ // Request ARM64 architecture on Apple Silicon machines
284+ if ( actions . IsRunningOnAppleSilicon ( ) )
285+ {
286+ cb . Argument ( "--architecture" ) .
287+ Argument ( "arm64" ) ;
288+ }
289+
290+ return cb . Argument ( "--install-dir" ) .
291+ Argument ( path ) . Script ;
292+ } ;
280293 }
281294
282- var dotnetInfo = new CommandBuilder ( actions ) .
295+ var dotnetInfo = new CommandBuilder ( actions , environment : MinimalEnvironment ) .
283296 RunCommand ( actions . PathCombine ( path , "dotnet" ) ) .
284297 Argument ( "--info" ) . Script ;
285298
@@ -311,7 +324,7 @@ BuildScript GetInstall(string pwsh) =>
311324
312325 private static BuildScript GetInstalledSdksScript ( IBuildActions actions )
313326 {
314- var listSdks = new CommandBuilder ( actions , silent : true ) .
327+ var listSdks = new CommandBuilder ( actions , silent : true , environment : MinimalEnvironment ) .
315328 RunCommand ( "dotnet" ) .
316329 Argument ( "--list-sdks" ) ;
317330 return listSdks . Script ;
0 commit comments