@@ -2282,7 +2282,12 @@ function Start-PSBootstrap {
22822282 [switch ]$BuildLinuxArm ,
22832283 [switch ]$Force ,
22842284 [Parameter (Mandatory = $true )]
2285- [ValidateSet (" Package" , " DotNet" , " Both" )]
2285+ # Package: Install dependencies for packaging tools (fpm, rpmbuild, WiX)
2286+ # DotNet: Install the .NET SDK
2287+ # Both: Package and DotNet scenarios
2288+ # Tools: Install .NET global tools (e.g., dotnet-format)
2289+ # All: Install all dependencies (packaging, .NET SDK, and tools)
2290+ [ValidateSet (" Package" , " DotNet" , " Both" , " Tools" , " All" )]
22862291 [string ]$Scenario = " Package"
22872292 )
22882293
@@ -2402,15 +2407,15 @@ function Start-PSBootstrap {
24022407
24032408 # Install [fpm](https://github.com/jordansissel/fpm)
24042409 # Note: fpm is now only needed for DEB and macOS packages; RPM packages use rpmbuild directly
2405- if ($Scenario -eq ' Both ' -or $Scenario -eq ' Package' ) {
2410+ if ($Scenario -in ' All ' , ' Both ' , ' Package' ) {
24062411 # Install fpm on Debian-based systems, macOS, and Mariner (where DEB packages are built)
24072412 if (($environment.IsLinux -and ($environment.IsDebianFamily -or $environment.IsMariner )) -or $environment.IsMacOS ) {
24082413 Install-GlobalGem - Sudo $sudo - GemName " dotenv" - GemVersion " 2.8.1"
24092414 Install-GlobalGem - Sudo $sudo - GemName " ffi" - GemVersion " 1.16.3"
24102415 Install-GlobalGem - Sudo $sudo - GemName " fpm" - GemVersion " 1.15.1"
24112416 Install-GlobalGem - Sudo $sudo - GemName " rexml" - GemVersion " 3.2.5"
24122417 }
2413-
2418+
24142419 # For RPM-based systems, ensure rpmbuild is available
24152420 if ($environment.IsLinux -and ($environment.IsRedHatFamily -or $environment.IsSUSEFamily -or $environment.IsMariner )) {
24162421 Write-Verbose - Verbose " Checking for rpmbuild..."
@@ -2422,7 +2427,7 @@ function Start-PSBootstrap {
24222427 }
24232428 }
24242429
2425- if ($Scenario -eq ' DotNet ' -or $Scenario -eq ' Both' ) {
2430+ if ($Scenario -in ' All ' , ' Both' , ' DotNet ' ) {
24262431
24272432 Write-Verbose - Verbose " Calling Find-Dotnet from Start-PSBootstrap"
24282433
@@ -2479,6 +2484,19 @@ function Start-PSBootstrap {
24792484 }
24802485 }
24812486
2487+ if ($Scenario -in ' All' , ' Tools' ) {
2488+ Write-Log - message " Installing .NET global tools"
2489+
2490+ # Ensure dotnet is available
2491+ Find-Dotnet
2492+
2493+ # Install dotnet-format
2494+ Write-Verbose - Verbose " Installing dotnet-format global tool"
2495+ Start-NativeExecution {
2496+ dotnet tool install -- global dotnet- format
2497+ }
2498+ }
2499+
24822500 if ($env: TF_BUILD ) {
24832501 Write-Verbose - Verbose " --- Start - Capturing nuget sources"
24842502 dotnet nuget list source -- format detailed
@@ -2646,6 +2664,63 @@ function Start-ResGen
26462664 }
26472665}
26482666
2667+ function Add-PSEnvironmentPath {
2668+ <#
2669+ . SYNOPSIS
2670+ Adds a path to the process PATH and persists to GitHub Actions workflow if running in GitHub Actions
2671+ . PARAMETER Path
2672+ Path to add to PATH
2673+ . PARAMETER Prepend
2674+ If specified, prepends the path instead of appending
2675+ #>
2676+ param (
2677+ [Parameter (Mandatory )]
2678+ [string ]$Path ,
2679+
2680+ [switch ]$Prepend
2681+ )
2682+
2683+ # Set in current process
2684+ if ($Prepend ) {
2685+ $env: PATH = $Path + [IO.Path ]::PathSeparator + $env: PATH
2686+ } else {
2687+ $env: PATH += [IO.Path ]::PathSeparator + $Path
2688+ }
2689+
2690+ # Persist to GitHub Actions workflow if running in GitHub Actions
2691+ if ($env: GITHUB_ACTIONS -eq ' true' ) {
2692+ Write-Verbose - Verbose " Adding $Path to GITHUB_PATH"
2693+ Add-Content - Path $env: GITHUB_PATH - Value $Path
2694+ }
2695+ }
2696+
2697+ function Set-PSEnvironmentVariable {
2698+ <#
2699+ . SYNOPSIS
2700+ Sets an environment variable in the process and persists to GitHub Actions workflow if running in GitHub Actions
2701+ . PARAMETER Name
2702+ The name of the environment variable
2703+ . PARAMETER Value
2704+ The value of the environment variable
2705+ #>
2706+ param (
2707+ [Parameter (Mandatory )]
2708+ [string ]$Name ,
2709+
2710+ [Parameter (Mandatory )]
2711+ [string ]$Value
2712+ )
2713+
2714+ # Set in current process
2715+ Set-Item - Path " env:$Name " - Value $Value
2716+
2717+ # Persist to GitHub Actions workflow if running in GitHub Actions
2718+ if ($env: GITHUB_ACTIONS -eq ' true' ) {
2719+ Write-Verbose - Verbose " Setting $Name in GITHUB_ENV"
2720+ Add-Content - Path $env: GITHUB_ENV - Value " $Name =$Value "
2721+ }
2722+ }
2723+
26492724function Find-Dotnet {
26502725 param (
26512726 [switch ] $SetDotnetRoot
@@ -2676,25 +2751,40 @@ function Find-Dotnet {
26762751 if ($dotnetCLIInstalledVersion -ne $chosenDotNetVersion ) {
26772752 Write-Warning " The 'dotnet' in the current path can't find SDK version ${dotnetCLIRequiredVersion} , prepending $dotnetPath to PATH."
26782753 # Globally installed dotnet doesn't have the required SDK version, prepend the user local dotnet location
2679- $ env: PATH = $dotnetPath + [ IO.Path ]::PathSeparator + $ env: PATH
2754+ Add-PSEnvironmentPath - Path $dotnetPath - Prepend
26802755
26812756 if ($SetDotnetRoot ) {
26822757 Write-Verbose - Verbose " Setting DOTNET_ROOT to $dotnetPath "
2683- $ env: DOTNET_ROOT = $dotnetPath
2758+ Set-PSEnvironmentVariable - Name ' DOTNET_ROOT' - Value $dotnetPath
26842759 }
26852760 } elseif ($SetDotnetRoot ) {
26862761 Write-Verbose - Verbose " Expected dotnet version found, setting DOTNET_ROOT to $dotnetPath "
2687- $ env: DOTNET_ROOT = $dotnetPath
2762+ Set-PSEnvironmentVariable - Name ' DOTNET_ROOT' - Value $dotnetPath
26882763 }
26892764 }
26902765 else {
26912766 Write-Warning " Could not find 'dotnet', appending $dotnetPath to PATH."
2692- $env: PATH += [IO.Path ]::PathSeparator + $dotnetPath
2767+ Add-PSEnvironmentPath - Path $dotnetPath
2768+
2769+ if ($SetDotnetRoot ) {
2770+ Write-Verbose - Verbose " Setting DOTNET_ROOT to $dotnetPath "
2771+ Set-PSEnvironmentVariable - Name ' DOTNET_ROOT' - Value $dotnetPath
2772+ }
26932773 }
26942774
26952775 if (-not (precheck ' dotnet' " Still could not find 'dotnet', restoring PATH." )) {
2776+ # Give up, restore original PATH. There is nothing to persist since we didn't make a change.
26962777 $env: PATH = $originalPath
26972778 }
2779+ elseif ($SetDotnetRoot ) {
2780+ # If we found dotnet, also add the global tools path to PATH
2781+ # Add .NET global tools to PATH when setting up the environment
2782+ $dotnetToolsPath = Join-Path $dotnetPath " tools"
2783+ if (Test-Path $dotnetToolsPath ) {
2784+ Write-Verbose - Verbose " Adding .NET tools path to PATH: $dotnetToolsPath "
2785+ Add-PSEnvironmentPath - Path $dotnetToolsPath
2786+ }
2787+ }
26982788}
26992789
27002790<#
0 commit comments