Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Regex route constraint support for Blazor routing -->
<BlazorRoutingEnableRegexConstraint Condition="'$(BlazorRoutingEnableRegexConstraint)' == ''">false</BlazorRoutingEnableRegexConstraint>

<!--
Enable diagnostics infrastructure (metrics, event sources, and HTTP activity propagation) by default for Blazor
WebAssembly apps. The low-level WASM runtime defaults these to 'false' to reduce download size via aggressive
trimming, but Blazor apps commonly use HttpClient with distributed tracing, structured logging, and metrics
(especially with .NET Aspire). Developers who want smaller binaries can opt out by setting
BlazorWebAssemblyDiagnosticsEnabled to 'false' or by setting the individual properties explicitly.
-->
<BlazorWebAssemblyDiagnosticsEnabled Condition="'$(BlazorWebAssemblyDiagnosticsEnabled)' == ''">true</BlazorWebAssemblyDiagnosticsEnabled>
<MetricsSupport Condition="'$(MetricsSupport)' == '' and '$(BlazorWebAssemblyDiagnosticsEnabled)' == 'true'">true</MetricsSupport>
<EventSourceSupport Condition="'$(EventSourceSupport)' == '' and '$(BlazorWebAssemblyDiagnosticsEnabled)' == 'true'">true</EventSourceSupport>
<HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == '' and '$(BlazorWebAssemblyDiagnosticsEnabled)' == 'true'">true</HttpActivityPropagationSupport>
</PropertyGroup>

<Import Sdk="Microsoft.NET.Sdk.Razor" Project="Sdk.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- EnableConfigurationBindingGenerator is enabled by default for trimmed apps, but Blazor WASM disables it by default -->
<EnableConfigurationBindingGenerator Condition="'$(EnableConfigurationBindingGenerator)' == ''">false</EnableConfigurationBindingGenerator>

<!--
Enable diagnostics infrastructure (metrics, event sources, and HTTP activity propagation) by default for Blazor
WebAssembly apps. The low-level WASM runtime defaults these to 'false' to reduce download size via aggressive
trimming, but Blazor apps commonly use HttpClient with distributed tracing, structured logging, and metrics
(especially with .NET Aspire). Developers who want smaller binaries can opt out by setting
BlazorWebAssemblyDiagnosticsEnabled to 'false' or by setting the individual properties explicitly.

These defaults are evaluated at Sdk.targets time (rather than Sdk.props time) so that the values can be set from
the project body of a .csproj, which is read before the SDK targets are imported. They must also be configured
before the feature switches are initialized to 'false' by the imported SDK targets below.
-->
<BlazorWebAssemblyDiagnosticsEnabled Condition="'$(BlazorWebAssemblyDiagnosticsEnabled)' == ''">true</BlazorWebAssemblyDiagnosticsEnabled>
Comment thread
javiercn marked this conversation as resolved.
<MetricsSupport Condition="'$(MetricsSupport)' == '' and '$(BlazorWebAssemblyDiagnosticsEnabled)' == 'true'">true</MetricsSupport>
<EventSourceSupport Condition="'$(EventSourceSupport)' == '' and '$(BlazorWebAssemblyDiagnosticsEnabled)' == 'true'">true</EventSourceSupport>
<HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == '' and '$(BlazorWebAssemblyDiagnosticsEnabled)' == 'true'">true</HttpActivityPropagationSupport>
</PropertyGroup>

<Import Sdk="Microsoft.NET.Sdk.Razor" Project="Sdk.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,26 @@ public void Build_Works()

[TestMethod]
[CoreMSBuildOnly]
[DataRow(null, "true", "true")]
[DataRow("false", "false", "false")]
public void Build_ResolvesBlazorDiagnosticsFeatureSwitches(string diagnosticsEnabled, string expectedDiagnosticsEnabled, string expectedFeatureValue)
[DataRow(null, false, "true", "true")]
[DataRow("false", false, "false", "false")]
// Setting the property from the project body must take effect (dotnet/sdk#55489): the defaults are
// evaluated at Sdk.targets time so a value set in the .csproj is honored, not just a global property.
[DataRow("false", true, "false", "false")]
[DataRow("true", true, "true", "true")]
public void Build_ResolvesBlazorDiagnosticsFeatureSwitches(string diagnosticsEnabled, bool setInProjectFile, string expectedDiagnosticsEnabled, string expectedFeatureValue)
{
var testInstance = CreateAspNetSdkTestAsset("BlazorWasmMinimal");

if (setInProjectFile && diagnosticsEnabled is not null)
{
testInstance.WithProjectChanges((project, doc) =>
{
var propertyGroup = new XElement("PropertyGroup");
propertyGroup.Add(new XElement("BlazorWebAssemblyDiagnosticsEnabled", diagnosticsEnabled));
doc.Root.Add(propertyGroup);
});
}

var build = CreateBuildCommand(testInstance);

var arguments = new List<string>
Expand All @@ -58,7 +73,7 @@ public void Build_ResolvesBlazorDiagnosticsFeatureSwitches(string diagnosticsEna
"-getProperty:HttpActivityPropagationSupport"
};

if (diagnosticsEnabled is not null)
if (!setInProjectFile && diagnosticsEnabled is not null)
{
arguments.Add($"/p:BlazorWebAssemblyDiagnosticsEnabled={diagnosticsEnabled}");
}
Expand Down
Loading