diff --git a/src/dotnet/ShellShim/WindowsEnvironmentPath.cs b/src/dotnet/ShellShim/WindowsEnvironmentPath.cs index da16b02c7..3194effd1 100644 --- a/src/dotnet/ShellShim/WindowsEnvironmentPath.cs +++ b/src/dotnet/ShellShim/WindowsEnvironmentPath.cs @@ -33,15 +33,26 @@ namespace Microsoft.DotNet.ShellShim var existingUserEnvPath = Environment.GetEnvironmentVariable(PathName, EnvironmentVariableTarget.User); - if (existingUserEnvPath.EndsWith(';')) + if (existingUserEnvPath == null) { - existingUserEnvPath = existingUserEnvPath.Substring(0, (existingUserEnvPath.Length - 1)); + Environment.SetEnvironmentVariable( + PathName, + _packageExecutablePath, + EnvironmentVariableTarget.User); } + else + { + if (existingUserEnvPath.EndsWith(';')) + { + existingUserEnvPath = existingUserEnvPath.Substring(0, (existingUserEnvPath.Length - 1)); + } - Environment.SetEnvironmentVariable( - PathName, - $"{existingUserEnvPath};{_packageExecutablePath}", - EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable( + PathName, + $"{existingUserEnvPath};{_packageExecutablePath}", + EnvironmentVariableTarget.User); + + } } private bool PackageExecutablePathExists()