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

[One .NET] place .aar files in NuGet packages properly #5242

Merged
merged 1 commit into from
Oct 27, 2020

Conversation

jonathanpeppers
Copy link
Member

Context: dotnet/sdk#14042 (comment)

We had been using an unfortunate hack to get the proper directory for
placing .aar files in NuGet packages:

<None Include="$(_AarOutputPath)" Pack="true" PackagePath="lib\$(TargetFramework)$(TargetPlatformVersion).0" />

Not only was the .0 weird, but it would also produce the wrong
result if the $(TargetFramework) was net5.0-android30:

lib\net5.0-android3030.0

Using an example from the NuGet team, we can run a run a target by
setting $(TargetsForTfmSpecificContentInPackage):

<PropertyGroup>
  <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_IncludeAarInNuGetPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

Then we can run the <GetNuGetShortFolderName/> MSBuild task to get
the NuGet folder name:

<GetNuGetShortFolderName
    TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
    TargetPlatformMoniker="$(TargetPlatformMoniker)">
  <Output TaskParameter="NuGetShortFolderName" PropertyName="_NuGetShortFolderName" />
</GetNuGetShortFolderName>

Lastly, we add to the @(TfmSpecificPackageFile) item group:

<ItemGroup>
  <TfmSpecificPackageFile Include="$(_AarOutputPath)" PackagePath="lib\$(_NuGetShortFolderName)" />
</ItemGroup>

Using these changes we can remove the @(None) item we were using
originally. I also updated a test to verify that net5.0-android30
works.

Context: dotnet/sdk#14042 (comment)

We had been using an unfortunate hack to get the proper directory for
placing `.aar` files in NuGet packages:

    <None Include="$(_AarOutputPath)" Pack="true" PackagePath="lib\$(TargetFramework)$(TargetPlatformVersion).0" />

Not only was the `.0` weird, but it would also produce the wrong
result if the `$(TargetFramework)` was `net5.0-android30`:

    lib\net5.0-android3030.0

Using an example from the NuGet team, we can run a run a target by
setting `$(TargetsForTfmSpecificContentInPackage)`:

    <PropertyGroup>
      <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_IncludeAarInNuGetPackage</TargetsForTfmSpecificContentInPackage>
    </PropertyGroup>

Then we can run the `<GetNuGetShortFolderName/>` MSBuild task to get
the NuGet folder name:

    <GetNuGetShortFolderName
        TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
        TargetPlatformMoniker="$(TargetPlatformMoniker)">
      <Output TaskParameter="NuGetShortFolderName" PropertyName="_NuGetShortFolderName" />
    </GetNuGetShortFolderName>

Lastly, we add to the `@(TfmSpecificPackageFile)` item group:

    <ItemGroup>
      <TfmSpecificPackageFile Include="$(_AarOutputPath)" PackagePath="lib\$(_NuGetShortFolderName)" />
    </ItemGroup>

Using these changes we can remove the `@(None)` item we were using
originally. I also updated a test to verify that `net5.0-android30`
works.
@jonathanpeppers jonathanpeppers merged commit aef815b into dotnet:master Oct 27, 2020
@jonathanpeppers jonathanpeppers deleted the dotnet-pack-fixes branch October 27, 2020 15:49
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants