Skip to content

Dotnetup: Modify PowerShell profile on Windows#54520

Open
dsplaisted wants to merge 2 commits into
dotnet:release/dnupfrom
dsplaisted:feature/dotnetup-pwsh-profile-windows
Open

Dotnetup: Modify PowerShell profile on Windows#54520
dsplaisted wants to merge 2 commits into
dotnet:release/dnupfrom
dsplaisted:feature/dotnetup-pwsh-profile-windows

Conversation

@dsplaisted
Copy link
Copy Markdown
Member

@dsplaisted dsplaisted commented May 29, 2026

Fix #53962

  • Sets up PowerShell profiles on Windows during init, if specified via installation mode.
  • Writes to both Windows PowerShell and PowerShell Core (pwsh) profile locations
  • Writes to profile.ps1, which applies to all PowerShell hosts, rather than Microsoft.PowerShell_profile.ps1, which only applies to the console host

There are other improvements to the experience and the code that we'd like to make, but this gets the basic functionality working.

Copilot AI review requested due to automatic review settings May 29, 2026 23:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Windows PowerShell profile support for dotnetup’s shell-profile environment setup, so init can configure PowerShell profiles on Windows in addition to Unix shells.

Changes:

  • Adds Windows PowerShell and PowerShell Core profile path resolution using profile.ps1.
  • Updates terminal profile modification flow to support Windows and system/user profile entries.
  • Adds/updates tests and design documentation for PowerShell profile paths and profile entry behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Installer/dotnetup.Library/Shell/PowerShellEnvShellProvider.cs Resolves PowerShell profile paths for Windows and switches to all-hosts profile.ps1.
src/Installer/dotnetup.Library/DotnetEnvironmentManager.cs Routes terminal profile updates through Windows/Unix-specific logic.
src/Installer/dotnetup.Library/IDotnetEnvironmentManager.cs Updates the interface signature and documentation for install-type-aware profile changes.
src/Installer/dotnetup.Library/Commands/Init/InitWorkflows.cs Calls profile modification with the updated API.
test/dotnetup.Tests/ShellProfileManagerTests.cs Adds coverage for Windows profile paths and environment manager profile entry behavior.
test/dotnetup.Tests/MockDotnetInstallManager.cs Updates test mock to match the interface signature.
test/dotnetup.Tests/DefaultInstallCommandTests.cs Updates expected Unix PowerShell profile filename.
documentation/general/dotnetup/designs/unix-environment-setup.md Documents Unix and Windows PowerShell profile locations.


return
[
Path.Combine(documentsFolder, WindowsPowerShellProfileFolder, ProfileFileName),
Comment on lines +346 to +361
if (installType == InstallType.System)
{
// System install: dotnet is assumed to be on PATH already (configured by the system
// installer / admin). The profile entry only adds dotnetup to PATH.
ShellProfileManager.AddProfileEntries(shellProvider, dotnetupPath, dotnetupOnly: true);
return;
}

// If the install root matches the default dotnetup-managed path, omit it from the profile
// entry so `print-env-script` falls back to its built-in default-detection logic. This
// keeps profile entries minimal and portable across user-resolved default paths.
string? profileDotnetRoot = DotnetupUtilities.PathsEqual(dotnetRoot, GetDefaultDotnetInstallPath())
? null
: dotnetRoot;

ShellProfileManager.AddProfileEntries(shellProvider, dotnetupPath, dotnetInstallPath: profileDotnetRoot);
shellProvider = ShellDetection.GetCurrentShellProviderOrThrow(shellProvider);

switch (installType)
if (installType == InstallType.System)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants