Skip to content

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

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-30110
Open

Move Blazor targets logic into conditional import to fix library project issues#30111
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-30110

Conversation

Copilot AI commented Jun 21, 2025

Copy link
Copy Markdown
Contributor

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 AI and others added 2 commits June 21, 2025 19:53
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
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 AI requested a review from mattleibow June 21, 2025 20:04
Comment thread .gitignore
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Copilot AI requested a review from mattleibow June 21, 2025 20:35
@mattleibow

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@kubaflo

kubaflo commented May 24, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/refactor-copilot-yml

@MauiBot

This comment has been minimized.

@kubaflo

kubaflo commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/enhanced-reviewer -p windows

@MauiBot

MauiBot commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Merge Conflict Detected — This PR has merge conflicts with its target branch. Please rebase onto the target branch and resolve the conflicts.

@kubaflo kubaflo 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.

Can you please resolve conflicts?

@kubaflo

kubaflo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

/review rerun

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

Labels

area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/windows

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

5 participants