Skip to content

Commit 8a1acdd

Browse files
authored
[Xamarin.Android.Build.Tasks] $(MetricsSupport)=false in "Release" (#9928)
Context: eb6397d Context: 200f843 Context: dotnet/runtime#89880 Context: dotnet/aspire#4684 Context: dotnet/maui#24365 Context: https://github.com/jfversluis/MauiAspire .NET 8 introduced use of System.Diagnostics.Metrics into `HttpClient`, which immediately slowed down .NET for Android app startup times (dotnet/runtime#89880). This was "fixed" by *disabling* use of Metrics within .NET for Android apps *by default* (eb6397d, 200f843). Support for Metrics could be re-enabled by setting the [`$(MetricsSupport)` MSBuild property][0]. .NET Aspire also uses System.Diagnostics.Metrics, and we'd like to allow Metrics to be available by default in that environment; see also dotnet/aspire#4684 and dotnet/maui#24365. Update the `$(MetricsSupport)` MSBuild property to be false by default only in "Release" configuration builds,, i.e. when `$(Optimize)`=true. [0]: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options
1 parent ba63153 commit 8a1acdd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<JsonSerializerIsReflectionEnabledByDefault Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' == '' and '$(TrimMode)' == 'partial'">true</JsonSerializerIsReflectionEnabledByDefault>
126126
<!-- Set to disable throwing behavior, see: https://github.com/dotnet/runtime/issues/109724 -->
127127
<_DefaultValueAttributeSupport Condition="'$(_DefaultValueAttributeSupport)' == '' and '$(TrimMode)' == 'partial'">true</_DefaultValueAttributeSupport>
128-
<MetricsSupport Condition="'$(MetricsSupport)' == ''">false</MetricsSupport>
128+
<MetricsSupport Condition="'$(MetricsSupport)' == '' and '$(Optimize)' == 'true'">false</MetricsSupport>
129129
<AndroidAvoidEmitForPerformance Condition="'$(AndroidAvoidEmitForPerformance)' == ''">$(AvoidEmitForPerformance)</AndroidAvoidEmitForPerformance>
130130
<AndroidAvoidEmitForPerformance Condition="'$(AndroidAvoidEmitForPerformance)' == ''">true</AndroidAvoidEmitForPerformance>
131131
<!-- Verify DI trimmability at development-time, but turn the validation off for production/trimmed builds. -->

tests/Mono.Android-Tests/Mono.Android-Tests/System/AppContextTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public void GetData (string name, string expected)
3939
new object [] {
4040
/* className */ "System.Diagnostics.Metrics.Meter, System.Diagnostics.DiagnosticSource",
4141
/* propertyName */ "<IsSupported>k__BackingField",
42+
#if DEBUG
43+
/* expected */ true,
44+
#else // !DEBUG
4245
/* expected */ false,
46+
#endif // !DEBUG
4347
},
4448
};
4549

0 commit comments

Comments
 (0)