Я не смог сделать намного лучше, чем шаги, которые я описал в своем вопросе, но я разработал приемлемый для границы сценарий для их запуска, хотя присоединение отладчика требует второго ручного шага. Я наверняка что-то упустил, но, возможно, опыт отладки все еще находится в стадии разработки.
param (
$Module = "MyModule",
$Framework = "netstandard2.0",
$Configuration = "Debug",
[switch] $ExitWhenComplete
)
try {
Push-Location $Module
& dotnet publish -f $Framework -c $Configuration
} finally {
Pop-Location
}
if ($LASTEXITCODE -ne 0) {
Write-Warning "Build failed";
exit 1;
}
$modulePath = [System.IO.Path]::Combine($PSScriptRoot, $Module, "bin", $Configuration, $Framework, "publish", "$Module.dll");
$command = "Import-Module `"$modulePath`"; ";
$command += "Write-Host `"You are now debugging $Module.dll - attach to PID `$pid`"; ";
$command += "Write-Host `"Type 'exit' to quit.`"; ";
$command += "Write-Host; ";
$testScript = "Launch.user.ps1";
if (Test-Path $testScript) {
$command += "Read-Host `"About to execute $testScript - hit enter to continue.`"; ";
$command += "& ./$testScript; ";
}
$command += "function prompt { write-host `"[debug] `" -ForegroundColor Yellow; } ";
if ($ExitWhenComplete) {
$command += "exit; ";
}
& pwsh -NoExit -NoProfile -Command $command;
Write-Host "Pwsh finished executing.";
Вы можете обновить $Module
, чтобы запустить этот модуль по умолчанию, и создать файл Launch.user.ps1 в том же каталоге, чтобы запустить команду при запуске сеанса отладки. Вам предлагается подключить отладчик до запуска сценария, но после загрузки модуля.
Как я уже сказал, вряд ли идеально, но, возможно, это поможет кому-то.