@@ -24,6 +24,10 @@ function RegisterExtractorPack(id)
24
24
local testMatch = false
25
25
local dotnetRunNeedsSeparator = false ;
26
26
local dotnetRunInjectionIndex = nil ;
27
+ -- A flag indicating whether we are in a position where we expect a sub-command such as `build`.
28
+ -- Once we have found one, we set this to `false` to not accidentally pick up on things that
29
+ -- look like sub-command names later on in the argument vector.
30
+ local inSubCommandPosition = true ;
27
31
local argv = compilerArguments .argv
28
32
if OperatingSystem == ' windows' then
29
33
-- let's hope that this split matches the escaping rules `dotnet` applies to command line arguments
@@ -35,30 +39,38 @@ function RegisterExtractorPack(id)
35
39
-- dotnet options start with either - or / (both are legal)
36
40
local firstCharacter = string.sub (arg , 1 , 1 )
37
41
if not (firstCharacter == ' -' ) and not (firstCharacter == ' /' ) then
38
- if (not match ) then
42
+ if (not match ) and inSubCommandPosition then
39
43
Log (1 , ' Dotnet subcommand detected: %s' , arg )
40
44
end
41
- if arg == ' build' or arg == ' msbuild' or arg == ' publish' or arg == ' pack' then
42
- match = true
43
- break
44
- end
45
- if arg == ' run' then
46
- -- for `dotnet run`, we need to make sure that `-p:UseSharedCompilation=false` is
47
- -- not passed in as an argument to the program that is run
48
- match = true
49
- dotnetRunNeedsSeparator = true
50
- dotnetRunInjectionIndex = i + 1
51
- end
52
- if arg == ' test' then
53
- match = true
54
- testMatch = true
45
+ -- only respond to strings that look like sub-command names if we have not yet
46
+ -- encountered something that looks like a sub-command
47
+ if inSubCommandPosition then
48
+ if arg == ' build' or arg == ' msbuild' or arg == ' publish' or arg == ' pack' then
49
+ match = true
50
+ break
51
+ end
52
+ if arg == ' run' then
53
+ -- for `dotnet run`, we need to make sure that `-p:UseSharedCompilation=false` is
54
+ -- not passed in as an argument to the program that is run
55
+ match = true
56
+ dotnetRunNeedsSeparator = true
57
+ dotnetRunInjectionIndex = i + 1
58
+ end
59
+ if arg == ' test' then
60
+ match = true
61
+ testMatch = true
62
+ end
55
63
end
64
+
56
65
-- for `dotnet test`, we should not append `-p:UseSharedCompilation=false` to the command line
57
66
-- if an `exe` or `dll` is passed as an argument as the call is forwarded to vstest.
58
67
if testMatch and (arg :match (' %.exe$' ) or arg :match (' %.dll' )) then
59
68
match = false
60
69
break
61
70
end
71
+
72
+ -- we have found a sub-command, ignore all strings that look like sub-command names from now on
73
+ inSubCommandPosition = false
62
74
end
63
75
-- if we see a separator to `dotnet run`, inject just prior to the existing separator
64
76
if arg == ' --' then
0 commit comments