Skip to content

Commit e244cbf

Browse files
[Xamarin.Android.Build.Tasks] skip C# binding-related targets (#6399)
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1334066 In traditional Xamarin.Android, a File -> New binding project emits the warning: BINDINGSGENERATOR warning BG8601: No '<package>' elements found. This happens until you add a Java library to actually bind. The warning doesn't happen in .NET 6 due to the `Condition`: <Target Name="_SetAndroidGenerateManagedBindings" Condition=" '$(UsingAndroidNETSdk)' != 'true' Or '@(InputJar->Count())' != '0' Or '@(EmbeddedJar->Count())' != '0' Or '@(LibraryProjectZip->Count())' != '0' "> <PropertyGroup> <!-- Used throughout to determine if C# binding-related targets should skip --> <_AndroidGenerateManagedBindings>true</_AndroidGenerateManagedBindings> </PropertyGroup> </Target> The `$(UsingAndroidNETSdk)` check makes the value always true in traditional Xamarin.Android. I think we can just remove this check, as the `Condition` has been working well in .NET 6. I added a new test for this scenario. The warning is gone now.
1 parent 572ede5 commit e244cbf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Core.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ It is shared between "legacy" binding projects and .NET 5 projects.
2929
</PropertyGroup>
3030

3131
<Target Name="_SetAndroidGenerateManagedBindings"
32-
Condition=" '$(UsingAndroidNETSdk)' != 'true' Or '@(InputJar->Count())' != '0' Or '@(EmbeddedJar->Count())' != '0' Or '@(LibraryProjectZip->Count())' != '0' ">
32+
Condition=" '@(InputJar->Count())' != '0' Or '@(EmbeddedJar->Count())' != '0' Or '@(LibraryProjectZip->Count())' != '0' ">
3333
<PropertyGroup>
3434
<!-- Used throughout to determine if C# binding-related targets should skip -->
3535
<_AndroidGenerateManagedBindings>true</_AndroidGenerateManagedBindings>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,19 @@ public void BindDefaultInterfaceMethods (string classParser)
595595
}
596596
}
597597

598+
[Test]
599+
[TestCaseSource (nameof (ClassParseOptions))]
600+
public void NothingToBind (string classParser)
601+
{
602+
var proj = new XamarinAndroidBindingProject {
603+
AndroidClassParser = classParser,
604+
};
605+
using (var b = CreateDllBuilder ()) {
606+
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
607+
b.AssertHasNoWarnings ();
608+
}
609+
}
610+
598611
[Test]
599612
[Category ("DotNetIgnore")] //TODO: @(LibraryProjectProperties) not supported yet in .NET 5+
600613
public void BugzillaBug11964 ()

0 commit comments

Comments
 (0)