9
9
using System . Runtime . CompilerServices ;
10
10
using System . Text ;
11
11
using System . Threading ;
12
+ using Microsoft . DotNet . CoreSetup . Test ;
13
+ using static Microsoft . DotNet . CoreSetup . Test . Constants ;
12
14
13
15
namespace Microsoft . DotNet . Cli . Build . Framework
14
16
{
@@ -22,11 +24,6 @@ public class Command
22
24
23
25
public Process Process { get ; }
24
26
25
- // Priority order of runnable suffixes to look for and run
26
- private static readonly string [ ] RunnableSuffixes = OperatingSystem . IsWindows ( )
27
- ? new string [ ] { ".exe" , ".cmd" , ".bat" }
28
- : new string [ ] { string . Empty } ;
29
-
30
27
private Command ( string executable , string args )
31
28
{
32
29
// Set the things we need
@@ -54,84 +51,17 @@ public static Command Create(string executable, IEnumerable<string> args)
54
51
55
52
public static Command Create ( string executable , string args )
56
53
{
57
- ResolveExecutablePath ( ref executable , ref args ) ;
58
-
59
- return new Command ( executable , args ) ;
60
- }
61
-
62
- private static void ResolveExecutablePath ( ref string executable , ref string args )
63
- {
64
- foreach ( string suffix in RunnableSuffixes )
65
- {
66
- var fullExecutable = Path . GetFullPath ( Path . Combine (
67
- AppContext . BaseDirectory , executable + suffix ) ) ;
68
-
69
- if ( File . Exists ( fullExecutable ) )
70
- {
71
- executable = fullExecutable ;
72
-
73
- // In priority order we've found the best runnable extension, so break.
74
- break ;
75
- }
76
- }
77
-
78
- // On Windows, we want to avoid using "cmd" if possible (it mangles the colors, and a bunch of other things)
79
- // So, do a quick path search to see if we can just directly invoke it
80
- var useCmd = ShouldUseCmd ( executable ) ;
81
-
82
- if ( useCmd )
83
- {
84
- var comSpec = System . Environment . GetEnvironmentVariable ( "ComSpec" ) ;
85
-
86
- // cmd doesn't like "foo.exe ", so we need to ensure that if
87
- // args is empty, we just run "foo.exe"
88
- if ( ! string . IsNullOrEmpty ( args ) )
89
- {
90
- executable = ( executable + " " + args ) . Replace ( "\" " , "\\ \" " ) ;
91
- }
92
- args = $ "/C \" { executable } \" ";
93
- executable = comSpec ;
94
- }
95
- }
96
-
97
- private static bool ShouldUseCmd ( string executable )
98
- {
99
- if ( OperatingSystem . IsWindows ( ) )
100
- {
101
- var extension = Path . GetExtension ( executable ) ;
102
- if ( ! string . IsNullOrEmpty ( extension ) )
103
- {
104
- return ! string . Equals ( extension , ".exe" , StringComparison . Ordinal ) ;
105
- }
106
- else if ( executable . Contains ( Path . DirectorySeparatorChar ) )
107
- {
108
- // It's a relative path without an extension
109
- if ( File . Exists ( executable + ".exe" ) )
110
- {
111
- // It refers to an exe!
112
- return false ;
113
- }
114
- }
115
- else
116
- {
117
- // Search the path to see if we can find it
118
- foreach ( var path in System . Environment . GetEnvironmentVariable ( "PATH" ) . Split ( Path . PathSeparator ) )
119
- {
120
- var candidate = Path . Combine ( path , executable + ".exe" ) ;
121
- if ( File . Exists ( candidate ) )
122
- {
123
- // We found an exe!
124
- return false ;
125
- }
126
- }
127
- }
128
-
129
- // It's a non-exe :(
130
- return true ;
131
- }
132
-
133
- // Non-windows never uses cmd
134
- return false ;
54
+ // Clear out .NET root and tracing environment variables by default
55
+ string oldPrefix = "COREHOST_" ;
56
+ string prefix = "DOTNET_HOST_" ;
57
+ return new Command ( executable , args )
58
+ . DotNetRoot ( null )
59
+ . RemoveEnvironmentVariable ( HostTracing . TraceLevelEnvironmentVariable )
60
+ . RemoveEnvironmentVariable ( HostTracing . TraceFileEnvironmentVariable )
61
+ . RemoveEnvironmentVariable ( HostTracing . VerbosityEnvironmentVariable )
62
+ . RemoveEnvironmentVariable ( HostTracing . TraceLevelEnvironmentVariable . Replace ( prefix , oldPrefix ) )
63
+ . RemoveEnvironmentVariable ( HostTracing . TraceFileEnvironmentVariable . Replace ( prefix , oldPrefix ) )
64
+ . RemoveEnvironmentVariable ( HostTracing . VerbosityEnvironmentVariable . Replace ( prefix , oldPrefix ) ) ;
135
65
}
136
66
137
67
public Command DisableDumps ( )
0 commit comments