Skip to content

Commit 2f83bdd

Browse files
[One .NET] update $(PackageTargetFallback) for NuGet packages (#5654)
Context: https://github.com/dotnet/designs/blob/38bffe6c03a149c80f1c3b22787f33c794e71c76/accepted/2021/net6.0-tfms/net6.0-tfms.md We don't have a complete implementation for .NET 6 & NuGet yet, so for for things to work *at all* we have `Microsoft.Android.Sdk.NuGet.targets` that contains workarounds that enable: * Given some NuGet package, `Foo.nupkg` * Try `lib/net6.0-android/Foo.dll` * Try `lib/monoandroid10.0/Foo.dll`, other `$(TFV)` etc. We can now test the above scenario with AndroidX NuGet packages: * dotnet/android-libraries#247 * https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json * `<PackageReference Include="Xamarin.AndroidX.AppCompat" Version = "1.2.0.7-net6preview01" />` Unfortunately, consuming `Xamarin.AndroidX.AppCompat` results in our build using `lib/monoandroid90/Xamarin.AndroidX.AppCompat.dll` over the .NET 6 one! I was able to reproduce this failure in the `XASdkTests.DotNetBuild()` test, as any `Release` build will fail during linking when using `MonoAndroid` assemblies without `KnownPackages.AddDotNetCompatPackages()`. To solve the problem, we need to list `net6.0-android30.0` in `$(PackageTargetFallback)`. Now .NET 6 packages are preferred over `MonoAndroid` ones. Lastly I added `MonoAndroid11.0`, because it was missing. Eventually I hope to delete `Microsoft.Android.Sdk.NuGet.targets` completely when the NuGet implementation of TFMs in .NET 6 is complete.
1 parent d28ba53 commit 2f83bdd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NuGet.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ This file contains *temporary* workarounds for NuGet in .NET 5.
1919
It doesn't suffer from: https://github.com/NuGet/docs.microsoft.com-nuget/issues/1955
2020
-->
2121
<PackageTargetFallback>
22+
net6.0-android$(TargetPlatformVersion).0;
23+
monoandroid11.0;
2224
monoandroid10.0;
2325
monoandroid90;
2426
monoandroid81;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease)
355355
{
356356
var proj = new XASdkProject {
357357
IsRelease = isRelease,
358+
ExtraNuGetConfigSources = {
359+
"https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json"
360+
},
361+
PackageReferences = {
362+
new Package { Id = "Xamarin.AndroidX.AppCompat", Version = "1.2.0.7-net6preview01" }
363+
},
358364
Sources = {
359365
new BuildItem ("EmbeddedResource", "Foo.resx") {
360366
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
@@ -364,6 +370,7 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease)
364370
},
365371
}
366372
};
373+
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": AndroidX.AppCompat.App.AppCompatActivity");
367374
proj.OtherBuildItems.Add (new AndroidItem.InputJar ("javaclasses.jar") {
368375
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
369376
});

0 commit comments

Comments
 (0)