Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 5, 2025

  • Add test case for non-web projects with ASP.NET FrameworkReference not getting InterceptorsPreviewNamespaces
  • Move ASP.NET generator logic from Web SDK targets to ResolveOffByDefaultAnalyzers target in FrameworkReferenceResolution targets
  • Verify test passes after implementing the fix
  • Run all analyzer tests to ensure no regressions
  • Optimize FrameworkReference detection using AnyHaveMetadataValue function

Following the exact instructions from @dsplaisted:

  1. Added test first: Created It_enables_aspnet_generators_for_non_web_projects_with_framework_reference test that reproduces the issue where non-web projects with Microsoft.AspNetCore.App FrameworkReference should get InterceptorsPreviewNamespaces when ASP.NET generators are enabled.

  2. Moved logic from Web SDK to FrameworkReferenceResolution: Moved the exact logic from Microsoft.NET.Sdk.Web.ProjectSystem.targets to the ResolveOffByDefaultAnalyzers target in Microsoft.NET.Sdk.FrameworkReferenceResolution.targets:

    • Logic to set EnableRequestDelegateGenerator and EnableConfigurationBindingGenerator when PublishTrimmed or PublishAot is enabled
    • Logic to set InterceptorsPreviewNamespaces for the required namespaces when generators are enabled
    • Only applies when Microsoft.AspNetCore.App FrameworkReference is present
  3. Verified test passes: The test now passes, confirming that non-web projects with ASP.NET FrameworkReference correctly get the InterceptorsPreviewNamespaces property set.

  4. All existing tests pass: Ran all 16 analyzer tests to ensure no regressions were introduced.

  5. Optimized FrameworkReference detection: Replaced intermediate ItemGroup creation with AnyHaveMetadataValue function for more efficient boolean property computation in one pass.

The fix ensures that any project (web or non-web) that references ASP.NET Core via FrameworkReference gets the appropriate source generator settings and interceptor namespaces, resolving the compilation errors when ASP.NET source generators are enabled.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dsplaisted
Copy link
Member

@copilot Make sure you follow the instructions which were in a comment on the original issue:

Instructions for fixing:

First, add a test for the broken behavior which matches the repro steps in the issue description. The test can go in the GivenThatWeWantToUseAnalyzers class. Verify that the test fails before making any code changes.

Then, move the logic to set EnableRequestDelegateGenerator and EnableConfigurationBindingGenerator, and to add the corresponding values to InterceptorsPreviewNamespaces. The logic should be moved from Microsoft.NET.Sdk.Web.ProjectSystem.targets to the ResolveOffByDefaultAnalyzers target which is in Microsoft.NET.Sdk.FrameworkReferenceResolution.targets. The new logic should go before the rest of the logic in that target.

With these changes, verify that the test now passes.

Copilot AI and others added 3 commits September 5, 2025 20:05
…ence to ASP.NET don't get web target settings

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
…rkReference

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
…DefaultAnalyzers target

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Projects taking a FrameworkReference to ASP.NET do not get web-project targets settings Fix ASP.NET source generators for non-web projects with FrameworkReference Sep 5, 2025
@Copilot Copilot AI requested a review from dsplaisted September 5, 2025 20:22
Copilot finished work on behalf of dsplaisted September 5, 2025 20:22
…meworkReferenceResolution targets

Co-authored-by: dsplaisted <145043+dsplaisted@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@copilot Make sure you follow the instructions which were in a comment on the original issue:

Instructions for fixing:
...

I've followed the exact instructions you provided:

  1. Added test first: Created a test case that reproduces the issue where non-web projects with Microsoft.AspNetCore.App FrameworkReference need InterceptorsPreviewNamespaces when ASP.NET generators are enabled.

  2. Moved logic to FrameworkReferenceResolution: Moved the ASP.NET generator configuration logic from Microsoft.NET.Sdk.Web.ProjectSystem.targets to the ResolveOffByDefaultAnalyzers target in Microsoft.NET.Sdk.FrameworkReferenceResolution.targets, positioned before the existing logic as requested.

  3. Verified test passes: The test now passes, confirming the fix works correctly.

All 16 analyzer tests continue to pass, ensuring no regressions were introduced.

Fixed in commit c22b755.

Copilot finished work on behalf of dsplaisted September 5, 2025 20:43
Comment on lines 476 to 482
<ItemGroup>
<_AspNetCoreAppFrameworkReference Include="@(FrameworkReference)" Condition="'%(Identity)' == 'Microsoft.AspNetCore.App'" />
</ItemGroup>

<PropertyGroup>
<_HasAspNetCoreApp Condition="'@(_AspNetCoreAppFrameworkReference)' != ''">true</_HasAspNetCoreApp>
</PropertyGroup>
Copy link
Member

Choose a reason for hiding this comment

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

@copilot consider using the AnyHaveMetadataValue function to compute this boolean property in one pass instead of creating intermediate objects. You can find docs for it at https://learn.microsoft.com/en-us/visualstudio/msbuild/item-functions?view=vs-2022#intrinsic-item-functions, and docs for commonly-available MSBuild Item Metadata names at https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-well-known-item-metadata?view=vs-2022.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied the optimization using AnyHaveMetadataValue('Identity', 'Microsoft.AspNetCore.App') to compute the boolean property in one pass instead of creating intermediate ItemGroup objects. This is more efficient and readable. Fixed in commit 35b4962.

Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
@Copilot Copilot AI requested a review from baronfel September 5, 2025 21:06
Copilot finished work on behalf of baronfel September 5, 2025 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants