Skip to content

Commit 552df30

Browse files
github-actions[bot]wtgodbeCopilot
authored
[release/11.0-preview2] Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references (#65547)
* Add FrameworkReference for non-SharedFx projects with SharedFx refs * Better approach * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove Transitive ref * fixup * Just to be sure * Feedback * Fixup * Revert "Fixup" This reverts commit c642e6b. * Revert "Feedback" This reverts commit 5076157. * Fixup * Revert "Fixup" This reverts commit d180f8a. * Test * Get error * Fixup --------- Co-authored-by: wigodbe <wigodbe@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4e09789 commit 552df30

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
</PropertyGroup>
132132

133133
<ItemGroup>
134+
<_RemovedAspNetKnownFrameworkReference Include="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App'))" />
134135
<KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" Remove="Microsoft.AspNetCore.App" />
135136
<KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
136137
</ItemGroup>

eng/targets/ResolveReferences.targets

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,38 @@
149149
Text="Redundant &lt;FrameworkReference&gt;. If you have an explicit item in the project file, you might be able to remove it. Some SDKs, like Microsoft.NET.Sdk.Web, add this implicitly." />
150150
</Target>
151151

152+
<!--
153+
NuGet pack reads framework references from restore assets. For affected SDK-pack projects, add a temporary
154+
framework reference during project evaluation so that it flows into the restore assets used by pack / GenerateNuspec.
155+
-->
156+
157+
<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' AND
158+
'$(IsPackable)' == 'true' AND
159+
'$(IsAspNetCoreApp)' != 'true' AND
160+
'@(_FrameworkProjectReference)' != '' AND
161+
'@(FrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' == '0'">
162+
<KnownFrameworkReference Include="@(_RemovedAspNetKnownFrameworkReference)" />
163+
<!-- Mark as IsTransitiveFrameworkReference to exclude the pruning data: https://github.com/dotnet/sdk/issues/53106 -->
164+
<FrameworkReference Include="Microsoft.AspNetCore.App" IsTransitiveFrameworkReference="true" DoNotResolve="true" />
165+
</ItemGroup>
166+
167+
<!-- Remove the referenced AspNetCore framework before it's resolved in ResolveFrameworkReferences. This lets us use our own references. -->
168+
<Target Name="_RemoveAspNetCoreFrameworkReference"
169+
BeforeTargets="ResolveFrameworkReferences" >
170+
<ItemGroup>
171+
<FrameworkReference Remove="@(FrameworkReference->WithMetadataValue('DoNotResolve', 'true'))" />
172+
</ItemGroup>
173+
</Target>
174+
175+
<!-- Remove Transtive Microsoft.Aspnetcore.App FrameworkReference, for projects referencing the affected projects above -->
176+
<Target Name="_RemoveAspNetCoreTransitiveFrameworkReference"
177+
BeforeTargets="AddTransitiveFrameworkReferences"
178+
Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" >
179+
<ItemGroup>
180+
<TransitiveFrameworkReference Remove="Microsoft.AspNetCore.App" />
181+
</ItemGroup>
182+
</Target>
183+
152184
<!--
153185
This target resolves remaining Reference items to Packages, if possible. If not, they are left as Reference
154186
items for the SDK to resolve. This executes on NuGet restore and during DesignTimeBuild. It should not run in

0 commit comments

Comments
 (0)