Skip to content

Conversation

@michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Oct 21, 2025

There appears to be a change in .NET 10 RC2 on how dotnet invokes 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

  • Add tracer support on MacOS and Linux when csc invoked directly. This also requires some special handling in the extractor to "detect" the correct compiler version information.
  • Add integration tests for windows and linux for creating a database using .NET 10 RC 2. Without modifying the integration test workflow, we need to rely on the autobuilder to install (and source) a dotnet installation. Unfortunately, this step fails for .NET 10 RC 2 on the Mac OS test runner - which is why it has been excluded from the integration test. It is possible for me to execute the test locally on my Mac when .NET 10 RC 2 is already installed. I don't think we should invest more time before we get the release version of .NET 10.

DCA looks good.

@github-actions github-actions bot added the C# label Oct 21, 2025
@michaelnebel michaelnebel requested a review from hvitved October 21, 2025 10:08
@michaelnebel michaelnebel marked this pull request as ready for review October 21, 2025 10:08
@michaelnebel michaelnebel requested a review from a team as a code owner October 21, 2025 10:08
Copilot AI review requested due to automatic review settings October 21, 2025 10:08
@michaelnebel michaelnebel changed the title C#: Tracer support for invoking csc directly. C#: Tracer support for invoking csc directly. Oct 21, 2025
Copy link
Contributor

Copilot AI left a 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 csc invocations
  • Updated compiler version detection to handle csc binary by reading version info from csc.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;
Copy link

Copilot AI Oct 21, 2025

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.

Suggested change
var compilerBinaryName = SpecifiedCompiler.EndsWith("csc") ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler;
var compilerBinaryName = Path.GetFileNameWithoutExtension(SpecifiedCompiler) == "csc" ? $"{SpecifiedCompiler}.dll" : SpecifiedCompiler;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

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.

Copy link
Contributor Author

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 😄

@michaelnebel michaelnebel force-pushed the csharp/dotnet10rc2traced branch from 0cb3b7b to af5622a Compare October 21, 2025 11:04
Copy link
Contributor

@hvitved hvitved left a 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?

prepend = { '--compiler', '"${compiler}"' },
order = ORDER_BEFORE
}),
CreatePatternMatcher({ '^csc$' }, MatchCompilerName,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@michaelnebel michaelnebel force-pushed the csharp/dotnet10rc2traced branch from e1e1172 to 47c751b Compare October 22, 2025 12:12
@michaelnebel michaelnebel requested a review from hvitved October 22, 2025 12:36
@michaelnebel michaelnebel merged commit 83343e1 into github:main Oct 22, 2025
23 checks passed
@michaelnebel michaelnebel deleted the csharp/dotnet10rc2traced branch October 22, 2025 13:37
gimlichael added a commit to gimlichael/Cuemon that referenced this pull request Oct 22, 2025
gimlichael added a commit to codebeltnet/xunit that referenced this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants