Skip to content

C#: Generate correct stub project references - #23351

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

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

Conversation

@michaelnebel

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 32120bbf01a61ba42e15b52c951d5c417f521af1

Dimension Assessment Rationale
Change confidence 9/10 ↑ Full make_stubs_all.py regeneration reproduces all six manual .csproj fixes.
↑ All 18 stub-dependent CodeQL tests pass with the generated project files.
↓ Validated only with the current package list and the .NET 11 SDK.
↓ Final commit differs from the validated tree only by a code comment and README wording.
Diagnosis confidence 9.5/10 ↑ Wrong versions came from parsing the dependency range minimum, not the restored version.
↑ Empty package folders come from ResolveConflicts in DependencyManager.cs, which keeps only the highest assembly version.
Evidence fit 9.5/10 ↑ The two causes explain each of the six manual edits needed for the .NET 11 stub update.

Regenerating the C# test stubs required manual .csproj fixes. This PR fixes the two causes in csharp/scripts/stubs/helpers.py.

  1. Restored dependency versions. A ProjectReference used the minimum version of the dependency range (for example [8.0.0, )), not the version NuGet actually restored, so it could point to a stub folder that doesn't exist. It now uses the resolved version from the project.assets.json target keys.
  2. Superseding frameworks. The webapp input project references Microsoft.AspNetCore.App, which ships newer copies of Microsoft.Extensions.* assemblies. The dependency manager keeps only the highest version of each assembly, so those types are stubbed only in the framework, and the package folders are left empty. A package whose DLLs were superseded this way now references the framework (for example Microsoft.Extensions.Http → _frameworks/Microsoft.AspNetCore.App).

Validation

  • Ran make_stubs_all.py (ServiceStack pinned to 10.5.0) and compared the output with the manually corrected stubs from the .NET 11 stub update (C#: Generate .NET 11 stubs #23345). All six manual fixes are reproduced. The only other differences are Microsoft.AspNetCore.App references on 10 more empty packages.
  • With these generated .csproj files, all 18 stub-dependent tests pass: SQL injection, Dapper, EntityFramework, NHibernate, ServiceStack and stored flow sources.

michaelnebel and others added 2 commits December 3, 2026 13:47
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>

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.

1 participant