Skip to content

Commit 6e5ed2f

Browse files
[Xamarin.Android.Build.Tasks] add Inputs/Outputs to _CheckAndroidHttpClientHandlerType
`dotnet trace` of a `dotnet new maui` project, I noticed this was happening on *any* build: 65.94ms xamarin.android.build.tasks!Xamarin.Android.Tasks.CheckClientHandlerType.RunTask() This was added in 311b41e, so it is only in main & .NET 8. Looking at the stack trace, most of the time is spent loading assemblies with Mono.Cecil. Let's add `Inputs` / `Outputs` to the `_CheckAndroidHttpClientHandlerType` MSBuild target, so it will skip on most incremental builds -- but run again if any MSBuild `.targets` or `.props` files change. With these changes in place, for incremental builds I now get: Target Name=_CheckAndroidHttpClientHandlerType Project=bar.csproj Skipping target "_CheckAndroidHttpClientHandlerType" because all output files are up-to-date with respect to the input files. I updated a test to check this target skips appropriately.
1 parent ec712da commit 6e5ed2f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ public void DotNetIncremental ([Values (true, false)] bool isRelease, [Values ("
10391039
var appBuilder = CreateDotNetBuilder (appA, Path.Combine (path, appA.ProjectName));
10401040
Assert.IsTrue (appBuilder.Build (runtimeIdentifier: runtimeIdentifier), $"{appA.ProjectName} should succeed");
10411041
appBuilder.AssertTargetIsNotSkipped ("CoreCompile");
1042+
appBuilder.AssertTargetIsNotSkipped ("_CheckAndroidHttpClientHandlerType");
10421043
if (isRelease) {
10431044
appBuilder.AssertTargetIsNotSkipped ("_RemoveRegisterAttribute");
10441045
appBuilder.AssertTargetIsNotSkipped ("_AndroidAot");
@@ -1047,6 +1048,7 @@ public void DotNetIncremental ([Values (true, false)] bool isRelease, [Values ("
10471048
// Build again, no changes
10481049
Assert.IsTrue (appBuilder.Build (runtimeIdentifier: runtimeIdentifier), $"{appA.ProjectName} should succeed");
10491050
appBuilder.AssertTargetIsSkipped ("CoreCompile");
1051+
appBuilder.AssertTargetIsSkipped ("_CheckAndroidHttpClientHandlerType");
10501052
if (isRelease) {
10511053
appBuilder.AssertTargetIsSkipped ("_RemoveRegisterAttribute");
10521054
appBuilder.AssertTargetIsSkipped ("_AndroidAotCompilation");

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
490490
</Target>
491491

492492
<Target Name="_CheckAndroidHttpClientHandlerType"
493-
Condition=" '$(AndroidHttpClientHandlerType)' != '' And '$(AndroidApplication)' == 'True' ">
493+
Condition=" '$(AndroidHttpClientHandlerType)' != '' And '$(AndroidApplication)' == 'True' "
494+
Inputs="@(_AndroidMSBuildAllProjects)"
495+
Outputs="$(_AndroidStampDirectory)_CheckAndroidHttpClientHandlerType.stamp">
494496
<PropertyGroup>
495497
<ValidAndroidHttpClientHandlerBaseType Condition="'$(UsingAndroidNETSdk)' != 'true'">System.Net.Http.HttpClientHandler, System.Net.Http</ValidAndroidHttpClientHandlerBaseType>
496498
<ValidAndroidHttpClientHandlerBaseType Condition="'$(UsingAndroidNETSdk)' == 'true'">System.Net.Http.HttpMessageHandler, System.Net.Http</ValidAndroidHttpClientHandlerBaseType>
@@ -500,6 +502,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
500502
ValidHandlerType="$(ValidAndroidHttpClientHandlerBaseType)"
501503
ResolvedAssemblies="$(OutDir)$(TargetFileName);@(ReferencePath);@(ReferenceDependencyPaths)"
502504
/>
505+
<Touch Files="$(_AndroidStampDirectory)_CheckAndroidHttpClientHandlerType.stamp" AlwaysCreate="true" />
503506
</Target>
504507

505508
<Target Name="_CheckNonIdealConfigurations">

0 commit comments

Comments
 (0)