From 07fc84de8cc41943cb2678d098afed4631466c72 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Thu, 29 Feb 2024 11:49:06 +0100 Subject: [PATCH] C#: Don't inject compiler flags when dotnet is used to execute an application. --- csharp/tools/tracing-config.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/csharp/tools/tracing-config.lua b/csharp/tools/tracing-config.lua index 55f803c5adb..5fc1cc8e80e 100644 --- a/csharp/tools/tracing-config.lua +++ b/csharp/tools/tracing-config.lua @@ -23,6 +23,10 @@ function RegisterExtractorPack(id) not isDotnetPath(arg) end + local function isPathToExecutable(path) + return path:match('%.exe$') or path:match('%.dll') + end + function DotnetMatcherBuild(compilerName, compilerPath, compilerArguments, _languageId) if not isDotnet(compilerName) then @@ -56,8 +60,16 @@ function RegisterExtractorPack(id) NativeArgumentsToArgv(compilerArguments.nativeArgumentPointer) end for i, arg in ipairs(argv) do + -- if dotnet is being used to execute any application except dotnet itself, we should + -- not inject any flags. + if not match and isPathToExecutable(arg) and not isDotnetPath(arg) then + Log(1, 'Execute a .NET application usage detected') + Log(1, 'Dotnet path-to-application detected: %s', arg) + break + end if isPossibleDotnetSubcommand(arg) then - if (not match) and inSubCommandPosition then + if not match and inSubCommandPosition then + Log(1, 'Execute a .NET SDK command usage detected') Log(1, 'Dotnet subcommand detected: %s', arg) end -- only respond to strings that look like sub-command names if we have not yet @@ -85,7 +97,7 @@ function RegisterExtractorPack(id) end -- for `dotnet test`, we should not append `-p:UseSharedCompilation=false` to the command line -- if an `exe` or `dll` is passed as an argument as the call is forwarded to vstest. - if testMatch and (arg:match('%.exe$') or arg:match('%.dll')) then + if testMatch and isPathToExecutable(arg) then match = false break end