Add null check for Environment.GetEnvironmentVariable (#8970)

This commit is contained in:
William Li 2018-04-03 14:36:19 -07:00 committed by GitHub
parent 0ca2c9fdc8
commit ef389bb6b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()