Skip to content

Fix BlazorWebAssemblyDiagnosticsEnabled so it can be set from a .csproj - #55537

Merged
javiercn merged 2 commits into
mainfrom
copilot/fix-blazorwebassembly-diagnostics-setting
Jul 31, 2026
Merged

Fix BlazorWebAssemblyDiagnosticsEnabled so it can be set from a .csproj#55537
javiercn merged 2 commits into
mainfrom
copilot/fix-blazorwebassembly-diagnostics-setting

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

BlazorWebAssemblyDiagnosticsEnabled and the diagnostics feature switches it drives (MetricsSupport, EventSourceSupport, HttpActivityPropagationSupport) were defaulted in Microsoft.NET.Sdk.BlazorWebAssembly.Current.props. MSBuild imports Sdk.props before the project body, so a value set in a .csproj was read too late — the documented opt-out only worked as a global property (/p:) or from Directory.Build.props.

<!-- Now takes effect: previously ignored because Sdk.props was already evaluated -->
<PropertyGroup>
  <BlazorWebAssemblyDiagnosticsEnabled>false</BlazorWebAssemblyDiagnosticsEnabled>
</PropertyGroup>

Changes

  • Moved the diagnostics defaults from Current.props to Current.targets — into the first PropertyGroup, which evaluates at Sdk.targets time (after the project body is read) and before the imported SDK targets initialize the switches to false. The property logic is otherwise unchanged, so the default (all switches true) and the existing /p: opt-out behave as before.
  • Extended Build_ResolvesBlazorDiagnosticsFeatureSwitches with cases that set the property in the project body (for both true and false), covering the .csproj path the previous /p:-only test missed.

Notes

  • Ordering matters: the block must run before the versioned 6_0/5_0.targets and the Mono WasmFeatures.props that default these switches to false when unset.
  • HttpActivityPropagationSupportSystem.Net.Http.EnableActivityPropagation mapping lives in the base .NET SDK targets and is unaffected; no extra RuntimeHostConfigurationOption is needed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@javiercn
javiercn marked this pull request as ready for review July 30, 2026 08:29
Copilot AI review requested due to automatic review settings July 30, 2026 08:29
@javiercn
javiercn requested a review from a team as a code owner July 30, 2026 08:29
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI changed the title [WIP] Fix BlazorWebAssemblyDiagnosticsEnabled setting in .csproj Fix BlazorWebAssemblyDiagnosticsEnabled so it can be set from a .csproj Jul 30, 2026
Copilot AI requested a review from javiercn July 30, 2026 08:30

Copilot AI 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.

Pull request overview

This PR adjusts the Blazor WebAssembly SDK’s MSBuild evaluation order so BlazorWebAssemblyDiagnosticsEnabled (and the derived feature-switch defaults) can be set from within a project file body, not only via global properties.

Changes:

  • Moves BlazorWebAssemblyDiagnosticsEnabled and the defaulting logic for MetricsSupport, EventSourceSupport, and HttpActivityPropagationSupport from Microsoft.NET.Sdk.BlazorWebAssembly.Current.props to Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets.
  • Extends Build_ResolvesBlazorDiagnosticsFeatureSwitches to validate behavior when BlazorWebAssemblyDiagnosticsEnabled is set inside the .csproj (not just via /p:).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/VanillaWasmTests.cs Expands the regression test matrix to cover setting BlazorWebAssemblyDiagnosticsEnabled in the project file body.
src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets Adds targets-time defaults for BlazorWebAssemblyDiagnosticsEnabled and the three derived feature properties so .csproj values are honored.
src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.props Removes the earlier props-time defaults that prevented .csproj body overrides from taking effect.

@javiercn
javiercn merged commit 7c53be7 into main Jul 31, 2026
23 checks passed
@javiercn
javiercn deleted the copilot/fix-blazorwebassembly-diagnostics-setting branch July 31, 2026 12:16
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 3, 2026
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.

BlazorWebAssemblyDiagnosticsEnabled cannot be set from a .csproj (conditions evaluated in Sdk.props)

4 participants