Add null check for Environment.GetEnvironmentVariable (#8970)
This commit is contained in:
parent
0ca2c9fdc8
commit
ef389bb6b3
1 changed files with 17 additions and 6 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue