dotnet / dotnet/sdk

`dotnetup init` switching to DotnetupDotnet mode does not remove old shell profile entries

Open
#54,543 0 comments 1 reaction 0 assignees View on GitHub
Area-CLI Area-dotnetup untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Prerequisites

- [x] I have read the [dotnetup documentation](https://github.com/dotnet/sdk/tree/release/dnup/documentation/general/dotnetup).
- [x] I have searched for [existing dotnetup issues](https://github.com/dotnet/sdk/issues?q=is%3Aissue%20state%3Aopen%20label%3Adotnetup).
- [x] I have searched for [existing dotnetup discussions](https://github.com/dotnet/sdk/discussions/categories/dotnetup).

### Issue type

Bug report

### Description

## Description

When a user runs `dotnetup init --interactive` and switches from `ShellProfile` mode to `DotnetupDotnet` mode, the previously written shell profile entries (in `profile.ps1` / `.bashrc` etc.) are not removed. This leaves stale environment configuration that continues to set `DOTNET_ROOT` and modify `PATH` in new terminals, even though the user explicitly opted out of shell profile integration.

## Steps to Reproduce

1. Run `dotnetup init --interactive` and select **Shell profile** mode.
2. Verify `profile.ps1` contains the `# dotnetup: begin` / `# dotnetup: end` block.
3. Run `dotnetup init --interactive` again and select **dotnetup dotnet** mode.
4. Open a new terminal.

## Expected Behavior

The `# dotnetup: begin` / `# dotnetup: end` block should be removed from all shell profile files when switching away from `ShellProfile` mode. The new terminal should not have `DOTNET_ROOT` set or dotnetup's dotnet prepended to `PATH`.

## Actual Behavior

The old profile entries remain. New terminals still source the dotnetup profile block, setting `DOTNET_ROOT` and prepending the dotnetup-managed dotnet path — contradicting the user's choice of `DotnetupDotnet` mode.

## Suggested Fix

In `InitWorkflows.InitWalkthrough`, when `previousPreference` was `ShellProfile` and the new `pathPreference` is not `ShellProfile`, call `ShellProfileManager.RemoveProfileEntries(...)` for all applicable shell providers to clean up the old entries. The `ShellProfileManager` already uses `# dotnetup: begin` / `# dotnetup: end` markers, so targeted removal should be straightforward.

### dotnetup version

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.