-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Tracer support for invoking csc directly.
#20663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C#: Tracer support for invoking csc directly.
#20663
Conversation
csc directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds tracer support for .NET 10 RC2, which changed how dotnet invokes the C# compiler. Instead of using dotnet exec csc.dll, RC2 directly invokes csc, which the tracer previously didn't handle. The changes enable proper tracing and extraction on macOS and Linux when csc is invoked directly.
Key Changes:
- Added pattern matcher in tracer configuration to intercept direct
cscinvocations - Updated compiler version detection to handle
cscbinary by reading version info fromcsc.dll - Added release note documenting the new tracing capability
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| csharp/tools/tracing-config.lua | Adds pattern matcher for direct csc compiler invocations |
| csharp/ql/lib/change-notes/2025-10-21-dotnet-rc2-tracing.md | Documents the new tracer support for .NET 10 RC2 |
| csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs | Updates version detection to read from csc.dll when compiler name is csc |
|
|
||
| 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; |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EndsWith check is too broad and could incorrectly match paths ending with 'csc' that aren't the compiler binary (e.g., /path/to/misc). Use Path.GetFileNameWithoutExtension(SpecifiedCompiler) == "csc" to ensure only the actual csc compiler binary is matched.
| var compilerBinaryName = SpecifiedCompiler.EndsWith("csc") ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler; | |
| var compilerBinaryName = Path.GetFileNameWithoutExtension(SpecifiedCompiler) == "csc" ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion - we do however need to take the file extension into account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we also need to make sure not to read the version information from a non-existing file 😄
0cb3b7b to
af5622a
Compare
hvitved
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this; tracer issues are annoying to debug. Could we add an integration test?
csharp/tools/tracing-config.lua
Outdated
| prepend = { '--compiler', '"${compiler}"' }, | ||
| order = ORDER_BEFORE | ||
| }), | ||
| CreatePatternMatcher({ '^csc$' }, MatchCompilerName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just include '^csc$' in the list above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the quotation in the above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per our offline discussion, the matchers have been merged, which means that the quotation has been removed for the .exe cases.
e1e1172 to
47c751b
Compare
There appears to be a change in .NET 10 RC2 on how
dotnetinvokes the compiler.I tested the following on a simple console application that can be build using
dotnet build.In .NET 9 / .NET 10 RC 1, the tracer sees the following intercept candidates
dotnet build(we intercept and disable shared compilation)dotnet exec csc.dll ...<- This is the compiler invocation that we catch in the tracer and use to call the extractor.However, in .NET RC 2, the tracer sees the following intercept candicates
dotnet build(we intercept and disable shared compilation)csc ...<-- This is the compiler invocation, but it "falls through" the patterns in the tracer.In this PR we
cscinvoked directly. This also requires some special handling in the extractor to "detect" the correct compiler version information.DCA looks good.