Skip to content

chore: Use .NET 11 Process APIs to simplify dev.cs #5363

Description

@Flash0ver

Summary

.NET 11 adds new Process APIs, that enables "the pit of success" for one-shot Process invocations:

With these, we can simplify our file-based apps dev.cs.

Detail

.NET 11 ships new one-shot Process APIs that make launching a process + waiting + capturing output a single deadlock-free call, so the hand-rolled process plumbing in dev.cs can be deleted and replaced with them.

The relevant .NET 11 APIs

New static methods on System.Diagnostics.Process (from the devblog):

  • Process.Run / Process.RunAsync — start, wait for exit, return a ProcessExitStatus (with ExitCode, Canceled, Signal). No output capture.
  • Process.RunAndCaptureText / …Async — same, but returns ProcessTextOutput with StandardOutput / StandardError captured together via multiplexing (no manual stream-draining, no deadlock risk).

Changes in dev.cs

dev.cs is a Cocona file-based CLI with two private helpers doing exactly what these APIs replace:

Current helper (~80 lines) Replace with
RunProcessAsync — builds ProcessStartInfo, Start(), try/catch, WaitForExitAsync(), returns ExitCode Process.RunAsync(fileName, args).ExitStatus.ExitCode
IsCommandAvailableAsync — runs which/where.exe, manually drains both streams with Task.WhenAll to avoid deadlock, checks exit code Process.RunAsync(...) (output is discarded anyway) or RunAndCaptureTextAsync if it wants the path

The manual stream-draining Task.WhenAll(ReadToEndAsync, ReadToEndAsync, WaitForExitAsync) in IsCommandAvailableAsync (dev.cs:198-201) is a footgun the new API is designed to eliminate.

Caveats worth flagging back to him

Caution

These are .NET 11 preview APIs - likely need to do this in version sentry-dotnet v7

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeNext MajorChanges scheduled for the next Major release.Repository MaintenanceTask

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions