@@ -29,22 +29,6 @@ public static class DotnetCli
2929
3030 private static int s_binlogCounter ;
3131
32- [ SuppressMessage ( "Style" , "IDE0032:Use auto property" , Justification = "It's causing some runtime bug" ) ]
33- private static int s_maxOutstandingCommand = Environment . ProcessorCount ;
34- private static SemaphoreSlim s_maxOutstandingCommands_semaphore = new ( s_maxOutstandingCommand , s_maxOutstandingCommand ) ;
35-
36- public static int MaxOutstandingCommands
37- {
38- get => s_maxOutstandingCommand ;
39-
40- set
41- {
42- s_maxOutstandingCommand = value ;
43- s_maxOutstandingCommands_semaphore . Dispose ( ) ;
44- s_maxOutstandingCommands_semaphore = new SemaphoreSlim ( s_maxOutstandingCommand , s_maxOutstandingCommand ) ;
45- }
46- }
47-
4832 public static bool DoNotRetry { get ; set ; }
4933
5034 public static async Task < DotnetMuxerResult > RunAsync (
@@ -61,69 +45,61 @@ public static async Task<DotnetMuxerResult> RunAsync(
6145 [ CallerMemberName ] string callerMemberName = "" ,
6246 CancellationToken cancellationToken = default )
6347 {
64- await s_maxOutstandingCommands_semaphore . WaitAsync ( cancellationToken ) ;
65- try
48+ environmentVariables ??= [ ] ;
49+ foreach ( DictionaryEntry entry in Environment . GetEnvironmentVariables ( ) )
6650 {
67- environmentVariables ??= [ ] ;
68- foreach ( DictionaryEntry entry in Environment . GetEnvironmentVariables ( ) )
51+ // Skip all unwanted environment variables.
52+ string ? key = entry . Key . ToString ( ) ;
53+ if ( WellKnownEnvironmentVariables . ToSkipEnvironmentVariables . Contains ( key , StringComparer . OrdinalIgnoreCase ) )
6954 {
70- // Skip all unwanted environment variables.
71- string ? key = entry . Key . ToString ( ) ;
72- if ( WellKnownEnvironmentVariables . ToSkipEnvironmentVariables . Contains ( key , StringComparer . OrdinalIgnoreCase ) )
73- {
74- continue ;
75- }
55+ continue ;
56+ }
7657
77- if ( disableCodeCoverage )
58+ if ( disableCodeCoverage )
59+ {
60+ // Disable the code coverage during the build.
61+ if ( CodeCoverageEnvironmentVariables . Contains ( key , StringComparer . OrdinalIgnoreCase ) )
7862 {
79- // Disable the code coverage during the build.
80- if ( CodeCoverageEnvironmentVariables . Contains ( key , StringComparer . OrdinalIgnoreCase ) )
81- {
82- continue ;
83- }
63+ continue ;
8464 }
85-
86- // We use TryAdd to let tests "overwrite" existing environment variables.
87- // Consider that the given dictionary has "TESTINGPLATFORM_UI_LANGUAGE" as a key.
88- // And also Environment.GetEnvironmentVariables() is returning TESTINGPLATFORM_UI_LANGUAGE.
89- // In that case, we do a "TryAdd" which effectively means the value from the original dictionary wins.
90- environmentVariables . TryAdd ( key ! , entry . Value ! . ToString ( ) ! ) ;
9165 }
9266
93- if ( disableTelemetry )
94- {
95- environmentVariables . Add ( "DOTNET_CLI_TELEMETRY_OPTOUT" , "1" ) ;
96- }
67+ // We use TryAdd to let tests "overwrite" existing environment variables.
68+ // Consider that the given dictionary has "TESTINGPLATFORM_UI_LANGUAGE" as a key.
69+ // And also Environment.GetEnvironmentVariables() is returning TESTINGPLATFORM_UI_LANGUAGE.
70+ // In that case, we do a "TryAdd" which effectively means the value from the original dictionary wins.
71+ environmentVariables . TryAdd ( key ! , entry . Value ! . ToString ( ) ! ) ;
72+ }
73+
74+ if ( disableTelemetry )
75+ {
76+ environmentVariables . Add ( "DOTNET_CLI_TELEMETRY_OPTOUT" , "1" ) ;
77+ }
9778
98- environmentVariables [ "NUGET_PACKAGES" ] = nugetGlobalPackagesFolder ;
79+ environmentVariables [ "NUGET_PACKAGES" ] = nugetGlobalPackagesFolder ;
9980
100- string extraArgs = warnAsError ? " -p:MSBuildTreatWarningsAsErrors=true" : string . Empty ;
101- extraArgs += suppressPreviewDotNetMessage ? " -p:SuppressNETCoreSdkPreviewMessage=true" : string . Empty ;
102- if ( args . IndexOf ( "-- " , StringComparison . Ordinal ) is int platformArgsIndex && platformArgsIndex > 0 )
103- {
104- args = args . Insert ( platformArgsIndex , extraArgs + " " ) ;
105- }
106- else
107- {
108- args += extraArgs ;
109- }
81+ string extraArgs = warnAsError ? " -p:MSBuildTreatWarningsAsErrors=true" : string . Empty ;
82+ extraArgs += suppressPreviewDotNetMessage ? " -p:SuppressNETCoreSdkPreviewMessage=true" : string . Empty ;
83+ if ( args . IndexOf ( "-- " , StringComparison . Ordinal ) is int platformArgsIndex && platformArgsIndex > 0 )
84+ {
85+ args = args . Insert ( platformArgsIndex , extraArgs + " " ) ;
86+ }
87+ else
88+ {
89+ args += extraArgs ;
90+ }
11091
111- if ( DoNotRetry )
112- {
113- return await CallTheMuxerAsync ( args , environmentVariables , workingDirectory , failIfReturnValueIsNotZero , callerMemberName , cancellationToken ) ;
114- }
115- else
116- {
117- IEnumerable < TimeSpan > delay = Backoff . ExponentialBackoff ( TimeSpan . FromSeconds ( 3 ) , retryCount , factor : 1.5 ) ;
118- return await Policy
119- . Handle < Exception > ( )
120- . WaitAndRetryAsync ( delay )
121- . ExecuteAsync ( async ct => await CallTheMuxerAsync ( args , environmentVariables , workingDirectory , failIfReturnValueIsNotZero , callerMemberName , ct ) , cancellationToken ) ;
122- }
92+ if ( DoNotRetry )
93+ {
94+ return await CallTheMuxerAsync ( args , environmentVariables , workingDirectory , failIfReturnValueIsNotZero , callerMemberName , cancellationToken ) ;
12395 }
124- finally
96+ else
12597 {
126- s_maxOutstandingCommands_semaphore . Release ( ) ;
98+ IEnumerable < TimeSpan > delay = Backoff . ExponentialBackoff ( TimeSpan . FromSeconds ( 3 ) , retryCount , factor : 1.5 ) ;
99+ return await Policy
100+ . Handle < Exception > ( )
101+ . WaitAndRetryAsync ( delay )
102+ . ExecuteAsync ( async ct => await CallTheMuxerAsync ( args , environmentVariables , workingDirectory , failIfReturnValueIsNotZero , callerMemberName , ct ) , cancellationToken ) ;
127103 }
128104 }
129105
0 commit comments