From e560ac197fed84bcaeb48455e9a7423e5574e3b9 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 21 Oct 2025 11:16:55 +0200 Subject: [PATCH 1/8] C#: Tracer support for invoking csc directly. --- .../Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs | 4 +++- csharp/tools/tracing-config.lua | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs index e52c79a17e19..6691ce51ab86 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs @@ -74,7 +74,9 @@ public CompilerVersion(Options options) specifiedFramework = compilerDir; } - var versionInfo = FileVersionInfo.GetVersionInfo(SpecifiedCompiler); + // If csc is specified as compiler name, then attempt to read the version information from csc.dll + var compilerBinaryName = SpecifiedCompiler.EndsWith("csc") ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler; + var versionInfo = FileVersionInfo.GetVersionInfo(compilerBinaryName); if (!knownCompilerNames.TryGetValue(versionInfo.OriginalFilename ?? string.Empty, out var vendor)) { SkipExtractionBecause("the compiler name is not recognised"); diff --git a/csharp/tools/tracing-config.lua b/csharp/tools/tracing-config.lua index a48a93c073c8..1bfa26ec20d0 100644 --- a/csharp/tools/tracing-config.lua +++ b/csharp/tools/tracing-config.lua @@ -226,6 +226,11 @@ function RegisterExtractorPack(id) prepend = { '--compiler', '"${compiler}"' }, order = ORDER_BEFORE }), + CreatePatternMatcher({ '^csc$' }, MatchCompilerName, + extractor, { + prepend = { '--compiler', '${compiler}' }, + order = ORDER_BEFORE + }), MsBuildMatcher, function(compilerName, compilerPath, compilerArguments, _languageId) -- handle cases like `dotnet exec csc.dll ` and `mono(-sgen64) csc.exe ` From 6bc15bcedc446d6c48613d6db7abcde0c772632d Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 21 Oct 2025 11:42:19 +0200 Subject: [PATCH 2/8] C#: Add change-note. --- csharp/ql/lib/change-notes/2025-10-21-dotnet-rc2-tracing.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 csharp/ql/lib/change-notes/2025-10-21-dotnet-rc2-tracing.md diff --git a/csharp/ql/lib/change-notes/2025-10-21-dotnet-rc2-tracing.md b/csharp/ql/lib/change-notes/2025-10-21-dotnet-rc2-tracing.md new file mode 100644 index 000000000000..b54f1e7d1b5d --- /dev/null +++ b/csharp/ql/lib/change-notes/2025-10-21-dotnet-rc2-tracing.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Added tracer support for macOS and Linux when the .NET CLI (`dotnet`) directly invokes the C# compiler (`csc`). This enhancement provides basic tracing and extraction capabilities for .NET 10 RC2 on these platforms. From af5622a60e8ff940f14c1e43856b9b21ece913a1 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 21 Oct 2025 13:03:53 +0200 Subject: [PATCH 3/8] C#: Address review comments. --- .../Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs index 6691ce51ab86..209f96e1bca9 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs @@ -75,7 +75,7 @@ public CompilerVersion(Options options) } // If csc is specified as compiler name, then attempt to read the version information from csc.dll - var compilerBinaryName = SpecifiedCompiler.EndsWith("csc") ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler; + var compilerBinaryName = Path.GetFileName(SpecifiedCompiler) == "csc" ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler; var versionInfo = FileVersionInfo.GetVersionInfo(compilerBinaryName); if (!knownCompilerNames.TryGetValue(versionInfo.OriginalFilename ?? string.Empty, out var vendor)) { From def522d122827323c768a88b0ef36099945df141 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 21 Oct 2025 13:12:21 +0200 Subject: [PATCH 4/8] C#: Make sure that the file exists before attempting to get version info. --- .../Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs index 209f96e1bca9..5429f2bba075 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs @@ -76,7 +76,7 @@ public CompilerVersion(Options options) // If csc is specified as compiler name, then attempt to read the version information from csc.dll var compilerBinaryName = Path.GetFileName(SpecifiedCompiler) == "csc" ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler; - var versionInfo = FileVersionInfo.GetVersionInfo(compilerBinaryName); + var versionInfo = FileVersionInfo.GetVersionInfo(File.Exists(compilerBinaryName) ? compilerBinaryName : SpecifiedCompiler); if (!knownCompilerNames.TryGetValue(versionInfo.OriginalFilename ?? string.Empty, out var vendor)) { SkipExtractionBecause("the compiler name is not recognised"); From d5ff9bf5d04348bd8eeed305f5f6f040a50281f1 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 22 Oct 2025 11:58:02 +0200 Subject: [PATCH 5/8] C#: Collapse tracer cases for csc, csc.exe and mcs.exe and remote quoting. --- csharp/tools/tracing-config.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/csharp/tools/tracing-config.lua b/csharp/tools/tracing-config.lua index 1bfa26ec20d0..13ede12a237e 100644 --- a/csharp/tools/tracing-config.lua +++ b/csharp/tools/tracing-config.lua @@ -221,12 +221,7 @@ function RegisterExtractorPack(id) } local posixMatchers = { DotnetMatcherBuild, - CreatePatternMatcher({ '^mcs%.exe$', '^csc%.exe$' }, MatchCompilerName, - extractor, { - prepend = { '--compiler', '"${compiler}"' }, - order = ORDER_BEFORE - }), - CreatePatternMatcher({ '^csc$' }, MatchCompilerName, + CreatePatternMatcher({ '^mcs%.exe$', '^csc%.exe$', '^csc$' }, MatchCompilerName, extractor, { prepend = { '--compiler', '${compiler}' }, order = ORDER_BEFORE From e14879ba336601259067290d4809a22f3a9d4339 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 22 Oct 2025 12:59:40 +0200 Subject: [PATCH 6/8] C#: Add integration test for DB creation using .NET 10 RC 2. --- .../all-platforms/dotnet_10_rc2/Program.cs | 1 + .../all-platforms/dotnet_10_rc2/dotnet_build.csproj | 10 ++++++++++ .../all-platforms/dotnet_10_rc2/global.json | 5 +++++ .../all-platforms/dotnet_10_rc2/test.py | 4 ++++ 4 files changed, 20 insertions(+) create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/Program.cs create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/dotnet_build.csproj create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/global.json create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/Program.cs b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/Program.cs new file mode 100644 index 000000000000..bd44629f7e23 --- /dev/null +++ b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/Program.cs @@ -0,0 +1 @@ +Console.WriteLine($"{string.Join(",", args)}"); diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/dotnet_build.csproj b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/dotnet_build.csproj new file mode 100644 index 000000000000..dfb40caafcf9 --- /dev/null +++ b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/dotnet_build.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/global.json b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/global.json new file mode 100644 index 000000000000..e870e2cf7bdd --- /dev/null +++ b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "10.0.100-rc.2.25502.107" + } +} diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py new file mode 100644 index 000000000000..a60901ae50d9 --- /dev/null +++ b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py @@ -0,0 +1,4 @@ +import os + +def test(codeql, csharp): + codeql.database.create(command="dotnet build") From 7a414089e47ba9d5def518b3476d62dc600eebe3 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 22 Oct 2025 13:25:23 +0200 Subject: [PATCH 7/8] C#: Use autobuilder instead of supplying build command. --- csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py index a60901ae50d9..1a68835d29c3 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py @@ -1,4 +1,4 @@ import os def test(codeql, csharp): - codeql.database.create(command="dotnet build") + codeql.database.create() From 47c751be327fd467030a2846c231a9bbd7b221b7 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 22 Oct 2025 14:06:37 +0200 Subject: [PATCH 8/8] C#: Only run integration test on windows and linux. --- .../{all-platforms => linux}/dotnet_10_rc2/Program.cs | 0 .../dotnet_10_rc2/dotnet_build.csproj | 0 .../{all-platforms => linux}/dotnet_10_rc2/global.json | 0 .../{all-platforms => linux}/dotnet_10_rc2/test.py | 2 ++ .../integration-tests/windows/dotnet_10_rc2/Program.cs | 1 + .../windows/dotnet_10_rc2/dotnet_build.csproj | 10 ++++++++++ .../windows/dotnet_10_rc2/global.json | 5 +++++ .../ql/integration-tests/windows/dotnet_10_rc2/test.py | 6 ++++++ 8 files changed, 24 insertions(+) rename csharp/ql/integration-tests/{all-platforms => linux}/dotnet_10_rc2/Program.cs (100%) rename csharp/ql/integration-tests/{all-platforms => linux}/dotnet_10_rc2/dotnet_build.csproj (100%) rename csharp/ql/integration-tests/{all-platforms => linux}/dotnet_10_rc2/global.json (100%) rename csharp/ql/integration-tests/{all-platforms => linux}/dotnet_10_rc2/test.py (68%) create mode 100644 csharp/ql/integration-tests/windows/dotnet_10_rc2/Program.cs create mode 100644 csharp/ql/integration-tests/windows/dotnet_10_rc2/dotnet_build.csproj create mode 100644 csharp/ql/integration-tests/windows/dotnet_10_rc2/global.json create mode 100644 csharp/ql/integration-tests/windows/dotnet_10_rc2/test.py diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/Program.cs b/csharp/ql/integration-tests/linux/dotnet_10_rc2/Program.cs similarity index 100% rename from csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/Program.cs rename to csharp/ql/integration-tests/linux/dotnet_10_rc2/Program.cs diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/dotnet_build.csproj b/csharp/ql/integration-tests/linux/dotnet_10_rc2/dotnet_build.csproj similarity index 100% rename from csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/dotnet_build.csproj rename to csharp/ql/integration-tests/linux/dotnet_10_rc2/dotnet_build.csproj diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/global.json b/csharp/ql/integration-tests/linux/dotnet_10_rc2/global.json similarity index 100% rename from csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/global.json rename to csharp/ql/integration-tests/linux/dotnet_10_rc2/global.json diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py b/csharp/ql/integration-tests/linux/dotnet_10_rc2/test.py similarity index 68% rename from csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py rename to csharp/ql/integration-tests/linux/dotnet_10_rc2/test.py index 1a68835d29c3..148626b1cb86 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_10_rc2/test.py +++ b/csharp/ql/integration-tests/linux/dotnet_10_rc2/test.py @@ -1,4 +1,6 @@ import os +import runs_on +@runs_on.linux def test(codeql, csharp): codeql.database.create() diff --git a/csharp/ql/integration-tests/windows/dotnet_10_rc2/Program.cs b/csharp/ql/integration-tests/windows/dotnet_10_rc2/Program.cs new file mode 100644 index 000000000000..bd44629f7e23 --- /dev/null +++ b/csharp/ql/integration-tests/windows/dotnet_10_rc2/Program.cs @@ -0,0 +1 @@ +Console.WriteLine($"{string.Join(",", args)}"); diff --git a/csharp/ql/integration-tests/windows/dotnet_10_rc2/dotnet_build.csproj b/csharp/ql/integration-tests/windows/dotnet_10_rc2/dotnet_build.csproj new file mode 100644 index 000000000000..dfb40caafcf9 --- /dev/null +++ b/csharp/ql/integration-tests/windows/dotnet_10_rc2/dotnet_build.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/csharp/ql/integration-tests/windows/dotnet_10_rc2/global.json b/csharp/ql/integration-tests/windows/dotnet_10_rc2/global.json new file mode 100644 index 000000000000..e870e2cf7bdd --- /dev/null +++ b/csharp/ql/integration-tests/windows/dotnet_10_rc2/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "10.0.100-rc.2.25502.107" + } +} diff --git a/csharp/ql/integration-tests/windows/dotnet_10_rc2/test.py b/csharp/ql/integration-tests/windows/dotnet_10_rc2/test.py new file mode 100644 index 000000000000..00905b67cd49 --- /dev/null +++ b/csharp/ql/integration-tests/windows/dotnet_10_rc2/test.py @@ -0,0 +1,6 @@ +import os +import runs_on + +@runs_on.windows +def test(codeql, csharp): + codeql.database.create()