@@ -271,6 +271,7 @@ function Start-PSBuild {
271271 [Parameter (ParameterSetName = " Default" )]
272272 [switch ]$NoPSModuleRestore ,
273273 [switch ]$CI ,
274+ [switch ]$ForMinimalSize ,
274275
275276 # Skips the step where the pwsh that's been built is used to create a configuration
276277 # Useful when changing parsing/compilation, since bugs there can mean we can't get past this step
@@ -321,6 +322,17 @@ function Start-PSBuild {
321322 if (" win-arm" , " win-arm64" -contains $Runtime -and -not $environment.IsWindows ) {
322323 throw " Cross compiling for win-arm or win-arm64 is only supported on Windows environment"
323324 }
325+
326+ if ($ForMinimalSize ) {
327+ if ($CrossGen ) {
328+ throw " Build for the minimal size requires the minimal disk footprint, so `CrossGen` is not allowed"
329+ }
330+
331+ if ($Runtime -and " linux-x64" , " win7-x64" , " osx-x64" -notcontains $Runtime ) {
332+ throw " Build for the minimal size is enabled only for following runtimes: 'linux-x64', 'win7-x64', 'osx-x64'"
333+ }
334+ }
335+
324336 function Stop-DevPowerShell {
325337 Get-Process pwsh* |
326338 Where-Object {
@@ -390,6 +402,7 @@ Fix steps:
390402 Verbose = $true
391403 SMAOnly = [bool ]$SMAOnly
392404 PSModuleRestore = $PSModuleRestore
405+ ForMinimalSize = $ForMinimalSize
393406 }
394407 $script :Options = New-PSOptions @OptionsArguments
395408
@@ -414,7 +427,7 @@ Fix steps:
414427 # Framework Dependent builds do not support ReadyToRun as it needs a specific runtime to optimize for.
415428 # The property is set in Powershell.Common.props file.
416429 # We override the property through the build command line.
417- if ($Options.Runtime -like ' fxdependent*' ) {
430+ if ($Options.Runtime -like ' fxdependent*' -or $ForMinimalSize ) {
418431 $Arguments += " /property:PublishReadyToRun=false"
419432 }
420433
@@ -467,18 +480,21 @@ Fix steps:
467480 Push-Location $Options.Top
468481
469482 if ($Options.Runtime -notlike ' fxdependent*' ) {
470- if ($Options.Runtime -like ' win-arm*' ) {
471- $Arguments += " /property:SDKToUse=Microsoft.NET.Sdk"
472- } else {
473- $Arguments += " /property:SDKToUse=Microsoft.NET.Sdk.WindowsDesktop"
483+ $sdkToUse = ' Microsoft.NET.Sdk'
484+ if ($Options.Runtime -like ' win7-*' -and ! $ForMinimalSize ) {
485+ # # WPF/WinForm and the PowerShell GraphicalHost assemblies are included
486+ # # when 'Microsoft.NET.Sdk.WindowsDesktop' is used.
487+ $sdkToUse = ' Microsoft.NET.Sdk.WindowsDesktop'
474488 }
475489
490+ $Arguments += " /property:SDKToUse=$sdkToUse "
491+
476492 Write-Log - message " Run dotnet $Arguments from $PWD "
477493 Start-NativeExecution { dotnet $Arguments }
478494 Write-Log - message " PowerShell output: $ ( $Options.Output ) "
479495
480496 if ($CrossGen ) {
481- # # fxdependent package cannot be CrossGen'ed
497+ # fxdependent package cannot be CrossGen'ed
482498 Start-CrossGen - PublishPath $publishPath - Runtime $script :Options.Runtime
483499 Write-Log - message " pwsh.exe with ngen binaries is available at: $ ( $Options.Output ) "
484500 }
@@ -651,14 +667,14 @@ function Restore-PSPackage
651667
652668 if ($Force -or (-not (Test-Path " $ ( $Options.Top ) /obj/project.assets.json" ))) {
653669
654- $sdkToUse = if (($Options.Runtime -eq ' fxdependent-win-desktop' -or $Options.Runtime -like ' win*' )) { # this is fxd or some windows runtime
655- if ($Options.Runtime -like ' win-arm*' ) {
656- ' Microsoft.NET.Sdk'
657- } else {
658- ' Microsoft.NET.Sdk.WindowsDesktop'
670+ if ($Options.Runtime -eq ' fxdependent-win-desktop' ) {
671+ $sdkToUse = ' Microsoft.NET.Sdk.WindowsDesktop'
672+ }
673+ else {
674+ $sdkToUse = ' Microsoft.NET.Sdk'
675+ if ($Options.Runtime -like ' win7-*' -and ! $Options.ForMinimalSize ) {
676+ $sdkToUse = ' Microsoft.NET.Sdk.WindowsDesktop'
659677 }
660- } else {
661- ' Microsoft.NET.Sdk'
662678 }
663679
664680 if ($PSModule.IsPresent ) {
@@ -784,7 +800,9 @@ function New-PSOptions {
784800
785801 [switch ]$SMAOnly ,
786802
787- [switch ]$PSModuleRestore
803+ [switch ]$PSModuleRestore ,
804+
805+ [switch ]$ForMinimalSize
788806 )
789807
790808 # Add .NET CLI tools to PATH
@@ -883,7 +901,8 @@ function New-PSOptions {
883901 - Configuration $Configuration `
884902 - PSModuleRestore $PSModuleRestore.IsPresent `
885903 - Framework $Framework `
886- - Output $Output
904+ - Output $Output `
905+ - ForMinimalSize $ForMinimalSize
887906}
888907
889908# Get the Options of the last build
@@ -3018,7 +3037,8 @@ function Restore-PSOptions {
30183037 - Configuration $options.Configuration `
30193038 - PSModuleRestore $options.PSModuleRestore `
30203039 - Framework $options.Framework `
3021- - Output $options.Output
3040+ - Output $options.Output `
3041+ - ForMinimalSize $options.ForMinimalSize
30223042
30233043 Set-PSOptions - Options $newOptions
30243044}
@@ -3055,7 +3075,11 @@ function New-PSOptionsObject
30553075
30563076 [Parameter (Mandatory )]
30573077 [String ]
3058- $Output
3078+ $Output ,
3079+
3080+ [Parameter (Mandatory )]
3081+ [Bool ]
3082+ $ForMinimalSize
30593083 )
30603084
30613085 return @ {
@@ -3067,6 +3091,7 @@ function New-PSOptionsObject
30673091 Output = $Output
30683092 CrossGen = $CrossGen
30693093 PSModuleRestore = $PSModuleRestore
3094+ ForMinimalSize = $ForMinimalSize
30703095 }
30713096}
30723097
0 commit comments