Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 7441627

Browse files
author
William Li
committed
Add DotnetTool path to avoid setting permanent env
In build machine on Windows
1 parent 4cc726e commit 7441627

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ private void RemoveCliGeneratedEnvironmentVariablesFrom(ProcessStartInfo psi)
230230

231231
private void AddEnvironmentVariablesTo(ProcessStartInfo psi)
232232
{
233+
AddDotnetToolPathToAvoidSettingPermanentEnvInBuildMachineOnWindows();
234+
233235
foreach (var item in Environment)
234236
{
235237
#if NET451
@@ -243,6 +245,31 @@ private void AddEnvironmentVariablesTo(ProcessStartInfo psi)
243245
psi.Environment["TEST_PACKAGES"] = System.Environment.GetEnvironmentVariable("TEST_PACKAGES");
244246
}
245247

248+
private void AddDotnetToolPathToAvoidSettingPermanentEnvInBuildMachineOnWindows()
249+
{
250+
string home = string.Empty;
251+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
252+
{
253+
if (!Environment.TryGetValue("DOTNET_CLI_HOME", out home) || string.IsNullOrEmpty(home))
254+
{
255+
Environment.TryGetValue("USERPROFILE", out home);
256+
}
257+
}
258+
259+
if (!string.IsNullOrEmpty(home))
260+
{
261+
var dotnetToolPath = Path.Combine(home, ".dotnet", "tools");
262+
if (Environment.ContainsKey("PATH"))
263+
{
264+
Environment["PATH"] = Environment["PATH"] + ";" + dotnetToolPath;
265+
}
266+
else
267+
{
268+
Environment["PATH"] = dotnetToolPath;
269+
}
270+
}
271+
}
272+
246273
private void AddWorkingDirectoryTo(ProcessStartInfo psi)
247274
{
248275
if (!string.IsNullOrWhiteSpace(WorkingDirectory))

0 commit comments

Comments
 (0)