Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] don't call <ResolveAssemblyReference/> directly #4215

Merged
merged 1 commit into from
Feb 5, 2020

Commits on Feb 4, 2020

  1. [Xamarin.Android.Build.Tasks] don't call <ResolveAssemblyReference/> …

    …directly
    
    I found that we were invoking the `<ResolveAssemblyReference/>`
    MSBuild task directly:
    
        <ResolveAssemblyReference ...>
          <Output TaskParameter="SatelliteFiles" ItemName="_AndroidResolvedSatellitePaths"/>
        </ResolveAssemblyReference>
    
    What is weird about this, is that `<ResolveAssemblyReference/>` is
    called twice during any Xamarin.Android build.
    
    But the first call from MSBuild itself returns the exact same
    assemblies we need here:
    
        Task ResolveAssemblyReference
            ...
            OutputItems
            ...
                ReferenceSatellitePaths
                    C:\src\weird-solutions\ClassLibrary1\bin\Debug\es\ClassLibrary3.resources.dll
    
    In this example I added a `Strings.resx` and `Strings.es.resx`. The
    satellite assembly contains the spanish translation.
    
    It looks to me we can just remove our call to the
    `<ResolveAssemblyReference/>` task, and use the public, built-in
    `@(ReferenceSatellitePaths)` item group instead.
    
    This worked, except for the in the case of
    `Mono.Android-Tests.csproj`. It contains resx files in the main app
    project, and these assemblies are not in `@(ReferenceSatellitePaths)`.
    
    Reviewing the code from MSBuild itself:
    
    https://github.com/microsoft/msbuild/blob/master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L4283-L4299
    
    We can use the item transform to get satellite assemblies for the
    current project:
    
        @(IntermediateSatelliteAssembliesWithTargetPath->'$(OutDir)%(Culture)\$(TargetName).resources.dll')
    
    There is not an item group for satellite assemblies in the current
    project. However, we merely end up with:
    
        <Target Name="_ResolveSatellitePaths" ...>
          <ItemGroup>
            <_AndroidResolvedSatellitePaths Include="@(ReferenceSatellitePaths)" />
            <_AndroidResolvedSatellitePaths Include="@(IntermediateSatelliteAssembliesWithTargetPath->'$(OutDir)%(Culture)\$(TargetName).resources.dll')" />
          </ItemGroup>
        </Target>
    
    This target will now take ~0ms instead of calling RAR.
    
    In a build with no changes for the SmartHotel360 app (which includes a
    netstandard project):
    
        Before:
        244 ms  ResolveAssemblyReference                   3 calls
        After:
        152 ms  ResolveAssemblyReference                   2 calls
    
    This looks like a ~92ms savings to every build.
    
    During the devloop, `Build` will run followed by `Install`. We will
    have 2x savings to the devloop in this case: ~184ms.
    jonathanpeppers committed Feb 4, 2020
    Configuration menu
    Copy the full SHA
    e254ae1 View commit details
    Browse the repository at this point in the history