dotnet / arcade

Tools that provide common build infrastructure for multiple .NET Foundation projects.
MIT License
657 stars 331 forks source link

Cannot use pwsh local tool with arcade #14532

Open jaredpar opened 4 months ago

jaredpar commented 4 months ago

The implementation of ExitWithExitCode means that we cannot use pwsh as a local tool in our repos. The implementation kills a number of processes, including dotnet. That means when you execute a script with dotnet pwsh example.ps1 the ExitWithExitCode will kill itself.

Example:

. "eng/common/tools.ps1"
$prepareMachine=$true
$ci=$true
ExitWithExitCode 0

Put that script in the root of a repo then execute it:

E:\code\wt\ros3 
⚡🔨 > dotnet pwsh .\example.ps1
Killing running build processes...
E:\code\wt\ros3 
⚡🔨 > $LASTEXITCODE
-1
jaredpar commented 4 months ago

Probably need to change Stop-Process to be

function Stop-Processes() {
  Write-Host 'Killing running build processes Roslyn style...'
  foreach ($processName in $processesToStopOnExit) {
    Get-Process -Name $processName -ErrorAction SilentlyContinue 
      ? { $_.ProcessId -ne $PID }
      | Stop-Process
  }
}

Really though, why we blanket kill dotnet here? What are we trying to achieve that forces us to do this?

dougbu commented 3 months ago

Really though, why we blanket kill dotnet here? What are we trying to achieve that forces us to do this?

I'm not sure of the history but suspect the process clean up is intended to ensure files are released before builds create artefacts.

In any case, there might be a workaround: Your builds could create a variable named processesToStopOnExit that's an array of strings naming what you want stopped. The default is @('msbuild', 'dotnet', 'vbcscompiler'). Passing @('msbuild', 'vbcscompiler') might do the trick for you @jaredpar.

If not, this seems like a quick fix. Feel free to open a PR 😁