Skip to content

Conversation

@michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Nov 13, 2025

This is the C# equivalent of this PR.

In this PR we add an extractor option for setting the directory for storing dependencies in BMN.
This is needed as a part of the Overlay work related to caching. Even though the action uses the environment variable directly for setting the directory, we still introduce this as an extractor option to streamline the implementation with Java.

@github-actions github-actions bot added the C# label Nov 13, 2025
@michaelnebel michaelnebel force-pushed the csharp/dependencycaching branch 4 times, most recently from 9126705 to 7223270 Compare November 14, 2025 13:42
@michaelnebel michaelnebel changed the title C#: Allow dependencies to be stored outside the SCRATCH_DIR. C#: Add extractor option for the dependency directory in BMN. Nov 17, 2025
@michaelnebel michaelnebel marked this pull request as ready for review November 17, 2025 12:05
@michaelnebel michaelnebel requested a review from a team as a code owner November 17, 2025 12:05
Copilot AI review requested due to automatic review settings November 17, 2025 12:05
Copilot finished reviewing on behalf of michaelnebel November 17, 2025 12:10
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 an extractor option for setting the dependency directory in buildless mode (standalone) extraction, enabling dependency caching. This aligns with the equivalent Java implementation for consistency across languages.

Key changes:

  • Introduced a new DependencyDirectory class that supports both cached and temporary directory modes
  • Added GetBuildlessDependencyDir() method to read the new CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS_DEPENDENCY_DIR environment variable
  • Replaced TemporaryDirectory with DependencyDirectory in NuGet package restoration classes

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyDirectory.cs New class that manages dependency directories, supporting both cached and temporary modes based on environment variable
csharp/extractor/Semmle.Util/EnvironmentVariables.cs Added method to retrieve the buildless dependency directory from environment variables
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs Updated to use DependencyDirectory instead of TemporaryDirectory for package storage
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs Updated to use DependencyDirectory and revised comment to reflect cached or temp location
csharp/codeql-extractor.yml Added buildless_dependency_dir option definition for the extractor configuration
csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/test.py Integration test that verifies the dependency directory option works correctly
csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/proj/standalone.csproj Test project file with Newtonsoft.Json dependency
csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/proj/global.json SDK version specification for the test project
csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/proj/Program.cs Minimal C# program for the integration test
csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/Assemblies.ql Query to verify that dependencies are found in the expected directory
csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/Assemblies.expected Expected output showing dependency in the configured directory

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to add support for this! Looks good from a consumer perspective. I added a few minor comments.

I don't know enough about the BMN extractor to know whether this change to NugetPackageRestorer covers all necessary cases, so someone more familiar with it should ideally review this too.

mbg
mbg previously approved these changes Nov 17, 2025
@michaelnebel michaelnebel requested a review from hvitved November 18, 2025 06:59
hvitved
hvitved previously approved these changes Nov 21, 2025
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.

LGTM

# dependency directory set above.
codeql.database.create(source_root="proj", build_mode="none")

# Check that the packages directory has been created in the dependecies folder.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo dependecies

@michaelnebel michaelnebel dismissed stale reviews from hvitved and mbg via 2440063 November 21, 2025 09:18
@michaelnebel michaelnebel force-pushed the csharp/dependencycaching branch from 2440063 to 5c454d2 Compare November 21, 2025 09:40
@michaelnebel michaelnebel requested a review from hvitved November 21, 2025 10:40
@michaelnebel
Copy link
Contributor Author

@hvitved : Had to rebase due to failing integration test (unrelated to this PR) - fixed the typo (this is the only change since the last review).

@michaelnebel michaelnebel merged commit 638c98b into github:main Nov 21, 2025
25 checks passed
@michaelnebel michaelnebel deleted the csharp/dependencycaching branch November 21, 2025 11:43
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.

3 participants