Skip to content

Commit

Permalink
[msbuild] Don't process assemblies over and over again in the UnpackL…
Browse files Browse the repository at this point in the history
…ibraryResources target. Fixes #16377. (#16416)

Fixes #16377 

MSbuild has the ability to run `Target` partially. However in order to make sure we can use this, both the `Inputs` and `Outputs` need to have a 1-1 mapping. MSBuild will then use this mapping to figure out which files have actually changed.
Then it will call the Target with only those files. 

In Xamarin.Android we make use of stamp files to provide this 1-1 mapping. We have a `pre` Target which will calculate an ItemGroup which will include a StampFile piece of metadata. We then use this new ItemGroup for both the `Inputs` and `Outputs`, thus meeting the 1-1 requirement. 

This PR updates the `_UnpackLibraryResources` to run partially. This will hopefully reduce the build time on incremental builds.
  • Loading branch information
dellis1972 committed Nov 17, 2022
1 parent 0f0dd30 commit 30405fd
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Expand Up @@ -1782,17 +1782,39 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</PackLibraryResources>
</Target>

<Target Name="_UnpackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="ResolveReferences;_CollectBundleResources">
<Target Name="_PrepareUnpackLibraryResources">
<PropertyGroup>
<_StampDirectory>$(IntermediateOutputPath)resourcestamps\</_StampDirectory>
</PropertyGroup>
<ItemGroup>
<_UnpackLibraryResourceItems Include="@(ReferencePath);@(ReferenceDependencyPaths)">
<StampFile>%(FileName).stamp</StampFile>
</_UnpackLibraryResourceItems>
</ItemGroup>
</Target>

<Target Name="_UnpackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="ResolveReferences;_CollectBundleResources;_PrepareUnpackLibraryResources"
Inputs="@(_UnpackLibraryResourceItems)"
Outputs="@(_UnpackLibraryResourceItems->'$(_StampDirectory)%(StampFile)')">
<MakeDir SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" Directories="$(_StampDirectory)" />
<UnpackLibraryResources
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Prefix="$(_EmbeddedResourcePrefix)"
NoOverwrite="@(_BundleResourceWithLogicalName)"
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferencedLibraries="@(ReferencePath);@(ReferenceDependencyPaths)">
ReferencedLibraries="@(_UnpackLibraryResourceItems)">
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
</UnpackLibraryResources>
<Touch
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
Files="@(_UnpackLibraryResourceItems->'$(_StampDirectory)%(StampFile)')"
AlwaysCreate="True"
>
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>

<Target Name="_ParseBundlerArguments">
Expand Down

4 comments on commit 30405fd

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.