From a67d1c6e06c47848b055b51ab7380e77201b2877 Mon Sep 17 00:00:00 2001 From: William Lee Date: Fri, 30 Mar 2018 16:05:41 -0700 Subject: [PATCH] Remove empty PATH in path resolver (#8943) --- src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs | 1 + src/dotnet/ShellShim/WindowsEnvironmentPath.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs b/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs index b8d85b3b7..de2a584df 100644 --- a/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs +++ b/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs @@ -47,6 +47,7 @@ namespace Microsoft.DotNet.Cli.Utils .GetEnvironmentVariable("PATH") .Split(s_pathSeparator) .Select(p => p.Trim(s_quote)) + .Where(p => !string.IsNullOrWhiteSpace(p)) .Select(p => ExpandTildeSlash(p))); _searchPaths = searchPaths; diff --git a/src/dotnet/ShellShim/WindowsEnvironmentPath.cs b/src/dotnet/ShellShim/WindowsEnvironmentPath.cs index 530f7c5bf..da16b02c7 100644 --- a/src/dotnet/ShellShim/WindowsEnvironmentPath.cs +++ b/src/dotnet/ShellShim/WindowsEnvironmentPath.cs @@ -33,6 +33,11 @@ namespace Microsoft.DotNet.ShellShim var existingUserEnvPath = Environment.GetEnvironmentVariable(PathName, EnvironmentVariableTarget.User); + if (existingUserEnvPath.EndsWith(';')) + { + existingUserEnvPath = existingUserEnvPath.Substring(0, (existingUserEnvPath.Length - 1)); + } + Environment.SetEnvironmentVariable( PathName, $"{existingUserEnvPath};{_packageExecutablePath}",