Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/skills/csharp-stubs/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: csharp-stubs
description: 'Refreshing the generated .NET/NuGet stubs in `csharp/ql/test/resources/stubs` used by C# CodeQL tests (for example when moving to a new .NET version): updating generator pins, regenerating with `make_stubs_all.py`, fixing generated project references, updating test `options` files and flow-summary expectations, and structuring the PR. Use when regenerating, upgrading or repairing those stubs.'
---

# Refreshing the generated C# test stubs

The generator lives in [`csharp/scripts/stubs`](../../../csharp/scripts/stubs) (see its `README.md`). Output goes to
`[DIR]/output/stubs` and is copied into [`csharp/ql/test/resources/stubs`](../../../csharp/ql/test/resources/stubs).

## Traps

* **Never delete files directly in the stubs root.** Only the subdirectories are generated; root-level `.cs` files are
hand-written.
* **Generated `ProjectReference` versions can be wrong.** The generator may use a dependency's NuGet *minimum* version
instead of the version actually restored. Check `project.assets.json` in the working directory and point each
reference at the generated folder that exists.
* **Types can be emitted into a different stub than expected.** If a project fails with missing types, it may need a
reference to a framework stub (e.g. `Microsoft.AspNetCore.App`) rather than a package stub.
* **Keep one version per library.** If several versions of a library are generated, keep one and retarget references.

## Steps

1. **Update the generator.** Bump the target framework and SDK in `helpers.py` (`net<N>.0`, `sdk_version`) and the
pinned versions in `packages_with_versions` in `make_stubs_all.py`. Make sure the matching .NET SDK is installed.
2. **Regenerate.** `python3 make_stubs_all.py /tmp/stubs-work` (from `csharp/scripts/stubs`). Keep the log.
3. **Replace generated stubs.** Delete every subdirectory of `csharp/ql/test/resources/stubs`, copy in the subdirectories
of `[DIR]/output/stubs`, then deduplicate versions.
4. **Fix compilation.** Build each generated project graph (`dotnet build` on the top-level `.csproj` files) and correct
references/project files until they compile.
5. **Update tests.** Rewrite stub paths in test `options` files
(`grep -rl "resources/stubs" csharp/ql/test --include=options`). Then run the affected tests with
`codeql test run`, and accept changed expectations only after reviewing them (typically
`csharp/ql/test/library-tests/dataflow/library/FlowSummaries*.expected`).
6. **Update the README** in `csharp/scripts/stubs` if the procedure or required SDK changed.

## Commit structure

Use separate commits so reviewers can tell generated output from manual edits (mirrors github/codeql#21069):

1. Generator pins and instructions.
2. Raw generated stubs (exactly as produced).
3. Manual fixes to generated projects.
4. Test `options` updates.
5. Updated test expectations.
Loading