Skip to content

Add ProcessStartOptions class with platform-aware path resolution#124271

Merged
adamsitnik merged 36 commits into
mainfrom
copilot/add-processstartoptions-class
Feb 18, 2026
Merged

Add ProcessStartOptions class with platform-aware path resolution#124271
adamsitnik merged 36 commits into
mainfrom
copilot/add-processstartoptions-class

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Description

Adds ProcessStartOptions class providing explicit path resolution and process configuration with platform-specific semantics.

Changes

API Surface

  • ProcessStartOptions(string fileName) - resolves executable path and validates existence
  • Properties: FileName, Arguments, Environment, WorkingDirectory, InheritedHandles, KillOnParentExit, CreateNewProcessGroup
  • Arguments, Environment, InheritedHandles use lazy allocation
  • Environment populated from Environment.GetEnvironmentVariables() using Dictionary<string, string?>
  • Null validation on Arguments and InheritedHandles setters
  • Constructor throws FileNotFoundException with localized message when path cannot be resolved or file doesn't exist

Path Resolution

  • Windows: appends .exe (except when path contains separators, ends with ., or has extension) → System32 → PATH (using ; separator)
  • Unix: PATH only (using : separator)
  • Current directory accessed only with explicit ./ (Unix) or .\ (Windows) prefix
  • Returns rooted, fully-qualified paths via Path.GetFullPath for non-fully-qualified inputs

Implementation Structure

  • ProcessUtils partial class consolidates shared logic:
    • ProcessUtils.cs - shared FindProgramInPath with comment explaining Unix permission checking
    • ProcessUtils.Windows.cs - private IsExecutable (forwards to File.Exists)
    • ProcessUtils.Unix.cs - private IsExecutable (validates executable permissions)
  • Process.Unix.cs calls ProcessStartOptions.ResolvePath (eliminates duplicate Process.ResolvePath)
  • Process.IsExecutable made internal for reuse
  • Uses Environment.SystemDirectory instead of duplicating GetSystemDirectoryW
  • Caches Windows directory in s_cachedWindowsDirectory
  • Localized error string SR.FileNotFoundResolvePath

Tests

  • 25 tests across 3 partial class files (base, Windows, Unix)
  • Target-typed new() syntax, [Theory] with [InlineData] for parameterized tests
  • Platform-specific assertions: EndsWith for paths (handles symlink variations), Path.GetFullPath for macOS /tmp symlinks
  • Conditional attributes: IsNotWindowsNanoServer, IsNotWindowsServerCore
  • Tests validate: lazy initialization, path resolution, platform separators, error cases

Customer Impact

Provides safer, more explicit alternative to ProcessStartInfo for scenarios requiring validated executable paths and controlled environment inheritance.

Testing

  • Manual: Library builds successfully
  • Automated: 25 unit tests covering path resolution, lazy initialization, platform-specific behavior, error cases

Example

// Resolves and validates path during construction
var options = new ProcessStartOptions("cmd");
Console.WriteLine(options.FileName); // C:\Windows\System32\cmd.exe

// Lazy-allocated collections
options.Arguments.Add("/c");
options.Arguments.Add("echo test");

// Environment inherits current process, modifiable
options.Environment["MY_VAR"] = "value";

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Copilot AI and others added 3 commits February 11, 2026 14:07
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ProcessStartOptions class to System.Diagnostics namespace Add ProcessStartOptions class with platform-aware path resolution Feb 11, 2026
Copilot AI requested a review from adamsitnik February 11, 2026 14:16

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address my feedback

Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStartOptionsTests.cs Outdated
Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStartOptionsTests.cs Outdated
Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStartOptionsTests.cs Outdated
Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStartOptionsTests.cs Outdated
Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStartOptionsTests.Unix.cs Outdated
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address my feedback

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address my feedback

Comment thread src/libraries/System.Diagnostics.Process/tests/ProcessStartOptionsTests.Unix.cs Outdated
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI requested a review from adamsitnik February 11, 2026 18:49
@adamsitnik adamsitnik requested a review from jkotas February 17, 2026 18:49
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI force-pushed the copilot/add-processstartoptions-class branch from bc6543b to c056741 Compare February 17, 2026 19:58
Copilot AI changed the title Add ProcessStartOptions class with simplified path resolution Add ProcessStartOptions class with platform-aware path resolution Feb 17, 2026
Comment thread src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj Outdated

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address my feedback

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
@jkotas

jkotas commented Feb 17, 2026

Copy link
Copy Markdown
Member

@copilot Address all feedback that was not addressed yet

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…mment

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@adamsitnik

Copy link
Copy Markdown
Member

/ba-g all build and test failures are known

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants