Skip to content

Commit

Permalink
[One .NET] place .aar files in NuGet packages properly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanpeppers committed Oct 27, 2020
1 parent d60d160 commit 09ba751
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,21 @@ projects.
/>
<ItemGroup>
<FileWrites Include="$(_AarOutputPath)" />
<None Include="$(_AarOutputPath)" Pack="true" PackagePath="lib\$(TargetFramework)$(TargetPlatformVersion).0" />
</ItemGroup>
</Target>

<PropertyGroup>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_IncludeAarInNuGetPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="_IncludeAarInNuGetPackage"
Condition=" '$(IncludeBuildOutput)' != 'false' and '$(AndroidApplication)' != 'true' and Exists('$(_AarOutputPath)') ">
<GetNuGetShortFolderName
TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
TargetPlatformMoniker="$(TargetPlatformMoniker)">
<Output TaskParameter="NuGetShortFolderName" PropertyName="_NuGetShortFolderName" />
</GetNuGetShortFolderName>
<ItemGroup>
<TfmSpecificPackageFile Include="$(_AarOutputPath)" PackagePath="lib\$(_NuGetShortFolderName)" />
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ public void DotNetBuildLibrary (bool isRelease, bool duplicateAar)
}

[Test]
public void DotNetPack ()
public void DotNetPack ([Values ("net5.0-android", "net5.0-android30")] string targetFramework)
{
var proj = new XASdkProject (outputType: "Library") {
TargetFramework = targetFramework,
IsRelease = true,
Sources = {
new BuildItem.Source ("Foo.cs") {
Expand Down

0 comments on commit 09ba751

Please sign in to comment.