Skip to content

Ensure GenAPI can resolve implementation-only assemblies when regenerating ref source - #130704

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-regenerate-ref-assemblies
Jul 16, 2026
Merged

tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-regenerate-ref-assemblies

Conversation

@tannergooding

Copy link
Copy Markdown
Member

When regenerating reference source via GenerateReferenceAssemblySource, GenAPI was unable to resolve the runtime implementation assemblies (System.Private.CoreLib and the shared framework, e.g. System.Private.Uri). These are implementation-only and never part of a reference pack, so they aren't on the assembly resolution path GenAPI derives from ReferencePath. Many core types -- enums (e.g. System.AttributeTargets), the init accessor marker (IsExternalInit), the System.Enum generic constraint, and System.Decimal -- are defined there and merely type-forwarded by the reference facades.

Without those assemblies GenAPI silently degrades its output:

  • enums emitted as raw integers, e.g. EditorBrowsableAttribute(1), AttributeUsageAttribute(32), DynamicallyAccessedMembersAttribute(1)
  • init accessors turned into set
  • where T : System.Enum constraint dropped to where T : struct
  • decimal rendered as System.Decimal

This is the source of most of the manual fixups the reference sources have accumulated, and it makes GenerateReferenceAssemblySource produce output that then has to be hand-corrected -- defeating the point of the tool.

This seeds GenAPILibPath (GenAPI's own resolution path, distinct from the compilation reference set) with the ReferencePath directories plus the CoreLib and shared framework directories, so the regenerated source is faithful. The target fires AfterTargets="ResolveAssemblyReferences" so ReferencePath is populated and it stays deterministic under parallel (/m) builds; it never runs on the cross-targeting outer build and doesn't touch the compile reference set.

Verified against System.Text.Json and Microsoft.Extensions.Hosting.Abstractions: enum-as-int, init->set, DynamicallyAccessedMembers-as-int and all "Unable to resolve assembly" warnings drop to 0.

Note

This PR description was drafted with the assistance of GitHub Copilot.

…ating ref source

Core types such as enums, the 'init' accessor marker, the System.Enum
constraint and System.Decimal are defined in System.Private.CoreLib and the
shared framework and merely type-forwarded by the reference facades. Those
implementation assemblies are never part of a reference pack, so GenAPI
couldn't resolve them and silently degraded its output (raw enum integers,
'init' accessors turned into 'set', dropped constraints, 'decimal' rendered as
'System.Decimal'). Seed GenAPILibPath with the CoreLib and shared framework
directories so the regenerated source is faithful.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

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.

Pull request overview

This PR updates the build engineering targets used by libraries to improve GenAPI’s assembly resolution when running GenerateReferenceAssemblySource, by ensuring GenAPI can locate runtime implementation-only assemblies (e.g., CoreLib / shared framework) in addition to the standard ReferencePath-derived inputs.

Changes:

  • Adds a new MSBuild target (AddImplementationAssembliesToGenAPIResolutionPath) that runs after ResolveAssemblyReferences to populate GenAPILibPath with ReferencePath directories plus runtime implementation assembly directories.
  • Limits the behavior to non-Mono builds and to cases where GenAPILibPath hasn’t already been explicitly set.
Show a summary per file
File Description
eng/resolveContract.targets Adds a new target to seed GenAPILibPath with additional implementation-assembly search paths for GenAPI when regenerating reference source.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread eng/resolveContract.targets Resolved
Copilot AI review requested due to automatic review settings July 14, 2026 19:29

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread eng/resolveContract.targets Resolved
@tannergooding
tannergooding merged commit 5149d67 into dotnet:main Jul 16, 2026
154 of 156 checks passed
@tannergooding
tannergooding deleted the tannergooding-regenerate-ref-assemblies branch July 16, 2026 19:53
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 17, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants