Skip to content

Commit a559c31

Browse files
committed
Fix check for dotnet folder in PATH
Copilot prompt: In #method:'Microsoft.DotNet.Tools.Bootstrapper.DotnetInstaller.ConfigureInstallType':4481-6459 what I meant by removing a folder from the path if it has dotnet in it was that you should check the contents of each folder and if it is a dotnet installation folder then it should be removed from the path. A simple way to check if it's a dotnet installation folder is if it has a dotnet executable in it.
1 parent 19f42c8 commit a559c31

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Installer/dnup/DotnetInstaller.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ public void ConfigureInstallType(SdkInstallType installType, string? dotnetRoot
109109
// Get current PATH
110110
var path = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User) ?? string.Empty;
111111
var pathEntries = path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList();
112-
// Remove all entries containing "dotnet" (case-insensitive)
113-
pathEntries = pathEntries.Where(p => !p.Contains("dotnet", StringComparison.OrdinalIgnoreCase)).ToList();
112+
string exeName = OperatingSystem.IsWindows() ? "dotnet.exe" : "dotnet";
113+
// Remove only actual dotnet installation folders from PATH
114+
pathEntries = pathEntries.Where(p => !File.Exists(Path.Combine(p, exeName))).ToList();
114115

115116
switch (installType)
116117
{

0 commit comments

Comments
 (0)