Skip to content

Comments

Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references#65478

Open
wtgodbe wants to merge 7 commits intomainfrom
wtgodbe/Vibeit
Open

Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references#65478
wtgodbe wants to merge 7 commits intomainfrom
wtgodbe/Vibeit

Conversation

@wtgodbe
Copy link
Member

@wtgodbe wtgodbe commented Feb 19, 2026

Fixes #65410

Projects that are are not in the shared framework, ship as packages, and have references to libraries that only ship in the shared framework, should wind up with a FrameworkReference to Microsoft.AspNetCore.App in their .nuspec. We used to have a custom post-build task that injected that FrameworkReference, but that went away in #64863.

This is a bit of a hack - we add a FrameworkReference to the affected projects, so that Restore can put that FrameworkRef into the generated assets file. Then we remove that FrameworkReference prior to ResolveFrameworkReferences so that the ProjectReferences get used instead. We also have to add a IsTransitiveFrameworkReference=true metadata to the FrameworkReference so that pruning warnings don't kick in: https://github.com/dotnet/sdk/blob/e90c4413024970eca97d05122243737aa207af11/src/Tasks/Microsoft.NET.Build.Tasks/GetPackagesToPrune.cs#L103-L104. It would be great if there was metadata we could set on the FrameworkReference (something like "NuspecOnly"), so that none of the references from the FrameworkReference would actually be raised, and pruning warnings wouldn't fire, but the FrameworkRef would still wind up in project.assets.json & the .nuspec.

@github-actions github-actions bot added needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Feb 19, 2026
@wtgodbe wtgodbe changed the title Add FrameworkReference for non-SharedFx projects with SharedFx refs Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references Feb 20, 2026
@wtgodbe wtgodbe marked this pull request as ready for review February 20, 2026 22:09
@wtgodbe wtgodbe requested a review from a team as a code owner February 20, 2026 22:09
Copilot AI review requested due to automatic review settings February 20, 2026 22:09
Copy link
Contributor

Copilot AI left a comment

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 adjusts the repo’s MSBuild reference-resolution/pack behavior so that non-SharedFx, packable projects that reference SharedFx-only assemblies can surface a Microsoft.AspNetCore.App framework dependency via restore assets (so packing can pick it up).

Changes:

  • Capture the Microsoft.AspNetCore.App KnownFrameworkReference before it’s removed globally, so it can be reintroduced conditionally.
  • Conditionally add a FrameworkReference to Microsoft.AspNetCore.App for packable, non-SharedFx projects with SharedFx-only project references, and add a target to remove the framework reference before ResolveFrameworkReferences.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
eng/targets/ResolveReferences.targets Adds conditional Microsoft.AspNetCore.App framework reference (and re-adds the known framework reference) plus a target that removes the framework reference before ResolveFrameworkReferences.
Directory.Build.targets Captures the KnownFrameworkReference for Microsoft.AspNetCore.App into an internal item before it gets removed.

Comment on lines +184 to +185
Condition="'@(TransitiveFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' != '0' AND
'$(UseAspNetCoreSharedRuntime)' != 'true'" >
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Condition="'@(TransitiveFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' != '0' AND
'$(UseAspNetCoreSharedRuntime)' != 'true'" >
Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" >

nit: this condition is redundant, I believe the remove is a noop if the item does not exist.

Comment on lines +182 to +183
BeforeTargets="AddTransitiveFrameworkReferences"
AfterTargets="ResolvePackageAssets"
Copy link
Member

Choose a reason for hiding this comment

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

Before and after here will not give this wiggle room, what it actually does it attempt to run it both before AddTransitiveFrameworkReferences and after ResolvePackageAssets. Whichever is first will win and the other will skip since it sees it already ran. IOW you can remove the BeforeTargets="AddTransitiveFrameworkReferences" as it does nothing right now.

'@(_FrameworkProjectReference)' != '' AND
'@(FrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' == '0'">
<KnownFrameworkReference Include="@(_RemovedAspNetKnownFrameworkReference)" />
<!-- Mark as IsTransitiveFrameworkReference to exclude the pruning data -->
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
<!-- Mark as IsTransitiveFrameworkReference to exclude the pruning data -->
<!-- Mark as IsTransitiveFrameworkReference to exclude the pruning data https://github.com/dotnet/sdk/issues/53106 -->

Comment on lines +173 to +174
'@(_FrameworkProjectReference)' != '' AND
'@(FrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' != '0'" >
Copy link
Member

Choose a reason for hiding this comment

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

Small suggestion - instead of duplicating the condition, just leave a marker on the one you add, then remove that here.

So above do :

      <FrameworkReference Include="Microsoft.AspNetCore.App" IsTransitiveFrameworkReference="true" DoNotResolve="true" /> 

Then here you can just do

      <FrameworkReference Remove="@(FrameworkReference->WithMetadataValue('DoNotResolve', 'true')'" />

And remove the entire condition on the target.

</PropertyGroup>

<ItemGroup>
<_RemovedAspNetKnownFrameworkReference Include="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App'))" />
Copy link
Member

Choose a reason for hiding this comment

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

Rather than removing this and adding it back did you consolidating the logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenApi] Microsoft.AspNetCore.OpenApi no longer includes Microsoft.AspNetCore.App framework reference

2 participants