Repository navigation
C#: Generate correct stub project references - #23351
Open
michaelnebel wants to merge 2 commits into
Open
michaelnebel wants to merge 2 commits into
michaelnebel wants to merge 2 commits into
Conversation
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
force-pushed
the
michaelnebel-stub-generator-improvements
branch
from
December 3, 2026 13:35
32120bb to
4fa08b1
Compare
Contributor
There was a problem hiding this comment.
🔵 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.jsoninstead 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)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The TLDR
project.assets.jsontarget keys instead of the minimum of its version range. This fixes problems with stubs not compiling.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↑ All 516 dependency entries in the restored
project.assets.jsonresolve 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
.csprojfixes. This PR addresses their causes in two commits:23f8acf87c3e— Use restored dependency versions. Resolves each dependency's project-reference version from theproject.assets.jsontarget keys instead of the minimum of its version range. A missing resolved dependency fails rather than falling back to a potentially incorrect version.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
make_stubs_all.pyat 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 additionalMicrosoft.AspNetCore.Appreferences in 10 package projects..csprojfiles, 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.mdwith #23345, which also edits that file.