Skip to content

Move Blazor targets logic into conditional import to fix library project issues #30111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 21, 2025

Problem

The Microsoft.AspNetCore.Components.WebView.Maui.targets file was always imported into all projects by NuGet, including library projects that don't need Blazor-specific build logic. This caused unnecessary overhead and potential conflicts for library projects that reference the BlazorWebView package.

Solution

Implemented a conditional import pattern by:

  1. Renamed existing Microsoft.AspNetCore.Components.WebView.Maui.targets to Microsoft.AspNetCore.Components.WebView.Maui.Sdk.targets
  2. Created new Microsoft.AspNetCore.Components.WebView.Maui.targets that conditionally imports the SDK targets

The new targets file only imports the actual Blazor build logic when:

  • OutputType=Exe OR
  • OutputType=WinExe OR
  • AndroidApplication=True OR
  • ImportMicrosoftAspNetCoreComponentsWebViewMauiTargets=True

Example

Before: All projects (including libraries) would import Blazor-specific targets

<!-- Always imported by NuGet -->
<Import Project="Microsoft.AspNetCore.Components.WebView.Maui.targets" />

After: Only application projects import the Blazor targets

<!-- New conditional wrapper -->
<Import Project="Microsoft.AspNetCore.Components.WebView.Maui.Sdk.targets" 
        Condition="'$(OutputType)' == 'Exe' OR '$(OutputType)' == 'WinExe' OR '$(AndroidApplication)' == 'True' OR '$(ImportMicrosoftAspNetCoreComponentsWebViewMauiTargets)' == 'True'" />

Testing

✅ Library projects (OutputType=Library) - targets not imported
✅ Application projects (OutputType=Exe/WinExe) - targets imported correctly
✅ Android applications (AndroidApplication=True) - targets imported correctly
✅ Override scenario - manual import flag works
✅ All existing BlazorWebView samples and tests continue to build successfully

This is a minimal, backward-compatible change that solves the import issue while preserving all existing functionality.

Fixes #30110.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Move the Blazor targets logic into a new file and conditionally import Move Blazor targets logic into conditional import to fix library project issues Jun 21, 2025
Copilot finished work on behalf of mattleibow June 21, 2025 20:04
@Copilot Copilot AI requested a review from mattleibow June 21, 2025 20:04
@Copilot Copilot AI requested a review from mattleibow June 21, 2025 20:35
Copilot finished work on behalf of mattleibow June 21, 2025 20:35
@mattleibow
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

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.

Move the Blazor targets logic into a new file and conditionally import
2 participants