This repository was archived by the owner on Apr 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
test/Microsoft.DotNet.Tools.Tests.Utilities/Commands Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) )
You can’t perform that action at this time.
0 commit comments