Move Blazor targets logic into conditional import to fix library project issues #30111
+128
−121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Microsoft.AspNetCore.Components.WebView.Maui.targets
toMicrosoft.AspNetCore.Components.WebView.Maui.Sdk.targets
Microsoft.AspNetCore.Components.WebView.Maui.targets
that conditionally imports the SDK targetsThe new targets file only imports the actual Blazor build logic when:
OutputType=Exe
OROutputType=WinExe
ORAndroidApplication=True
ORImportMicrosoftAspNetCoreComponentsWebViewMauiTargets=True
Example
Before: All projects (including libraries) would import Blazor-specific targets
After: Only application projects import the Blazor targets
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.