Skip to content

C#: Generate correct stub project references - #23351

Open
michaelnebel wants to merge 2 commits into
github:mainfrom
michaelnebel:michaelnebel-stub-generator-improvements
Open

michaelnebel wants to merge 2 commits into
github:mainfrom
michaelnebel:michaelnebel-stub-generator-improvements

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

The TLDR

  • First commit: Use restored dependency versions from project.assets.json target keys instead of the minimum of its version range. This fixes problems with stubs not compiling.
  • Second commit: Reference superseding frameworks. When dependency-manager conflict resolution retains a framework's newer assembly instead of a package's copy, adds a reference from the package project to the framework containing the generated stubs.

This should generally improve the generated stubs and required fewer (maybe none) manual changes afterwards.

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 4fa08b110db15e54f4c5ac40727d108f9751877e

Dimension Assessment Rationale
Change confidence 9/10 ↑ Full regeneration at this revision reproduced all six manual project-reference fixes from #23345.
↑ All 516 dependency entries in the restored project.assets.json resolve to a restored package version.
↑ 18 selected stub-dependent CodeQL tests passed with the generated project files from an earlier revision.
↓ Validated only with the .NET 11 SDK and the current package list, with ServiceStack pinned to 10.5.0.
↓ Tests were not rerun after the unreached version-range fallback was removed.

Regenerating the C# test stubs required manual .csproj fixes. This PR addresses their causes in two commits:

  1. 23f8acf87c3e — Use restored dependency versions. Resolves each dependency's project-reference version from the project.assets.json target keys instead of the minimum of its version range. A missing resolved dependency fails rather than falling back to a potentially incorrect version.
  2. 4fa08b110db1 — Reference superseding frameworks. When dependency-manager conflict resolution retains a framework's newer assembly instead of a package's copy, adds a reference from the package project to the framework containing the generated stubs. The package projects remain as pass-through references. It also updates the README, noting that generated stubs might still need manual changes.

Validation

  • Ran make_stubs_all.py at the final revision with ServiceStack pinned to 10.5.0, matching the .NET 11 stub update (C#: Generate .NET 11 stubs #23345). The generated output reproduces all six manual fixes and otherwise matches the generated stubs there, except for additional Microsoft.AspNetCore.App references in 10 package projects.
  • With the earlier generated .csproj files, 18 selected stub-dependent tests passed: SQL injection, Dapper, EntityFramework, NHibernate, ServiceStack and stored flow sources.

Note

Expect a small conflict in csharp/scripts/stubs/README.md with #23345, which also edits that file.

michaelnebel and others added 2 commits December 3, 2026 14:35
Project references used the minimum version of a dependency's version range,
which may differ from the version that was restored and stubbed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The dependency manager keeps only the highest version of each assembly, so
package assemblies superseded by a framework are stubbed in the framework.
Reference that framework from the package project.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@michaelnebel
michaelnebel force-pushed the michaelnebel-stub-generator-improvements branch from 32120bb to 4fa08b1 Compare December 3, 2026 13:35
@michaelnebel
michaelnebel requested an adaptive review from Copilot December 3, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The changes alter transitive stub-project references through interacting NuGet resolution, assembly precedence, and framework ownership, requiring cross-project type-resolution analysis beyond localized review.

No open issues 🎉

What changed in this PR

This PR improves C# test-stub generation by producing project references that match restored dependencies and framework-provided stubs.

Changes:

  • Use resolved dependency versions from project.assets.json instead of version-range minimums.
  • Add framework references when framework assemblies supersede package assemblies.
  • Document the reference behavior and remaining possibility of manual fixes.
File Description
csharp/​scripts/​stubs/​README.md Explains generated references and remaining manual-fix caveats.
csharp/​scripts/​stubs/​helpers.py Resolves restored versions and adds references to superseding frameworks.

Review effort: Balanced (adaptive)

@michaelnebel
michaelnebel marked this pull request as ready for review December 3, 2026 14:08
@michaelnebel
michaelnebel requested a review from a team as a code owner December 3, 2026 14:08
@michaelnebel
michaelnebel requested a review from hvitved December 3, 2026 14:08

This branch has not been deployed

No deployments
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