dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 532 forks source link

[Xamarin.Android.Build.Tasks] add missing `Condition` in `AutoImport.props` #9463

Closed jonathanpeppers closed 1 week ago

jonathanpeppers commented 3 weeks ago

One of the "gotchas" with AutoImport.props, is the file is imported by literally all .NET projects. Even .NET 8 and .NET 9 Android projects import their files on top of each other...

This means every <ItemGroup> needs a Condition that checks:

<ItemGroup>s in AutoImport.props should have, something like:

<ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'android' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '9.0')) ">

$(EnableDefaultAndroidItems) checks also work for some cases, but .NET MAUI turns this off in favor of their own wildcards:

https://github.com/dotnet/maui/blob/f269ef3de701043910c941bbbfcbdb7422cc245c/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.Before.targets#L10

jpobst commented 3 weeks ago

Can this also add some sort of @(EnableAndroidPackagingOptions) property users can use to opt out of this?

Apparently this does not opt out of them:

    <ItemGroup>
      <AndroidPackagingOptionsExclude Remove="@(AndroidPackagingOptionsExclude)" />
    </ItemGroup>

and they have to put it behind a target instead, which makes it very hard for most users to figure out how to opt-out:

  <Target Name="_Foo" BeforeTargets="_PrepareBuildApk">
    <ItemGroup>
      <AndroidPackagingOptionsExclude Remove="@(AndroidPackagingOptionsExclude)" />
    </ItemGroup>
  </Target>

Source

jonathanpeppers commented 3 weeks ago

The idea of AutoImport.props, it is before your project, and you can override/clear them:

<AndroidPackagingOptionsExclude Remove="DebugProbesKt.bin" />
<!-- Or just all of them -->
<AndroidPackagingOptionsExclude Remove="@(AndroidPackagingOptionsExclude)" />
jonathanpeppers commented 3 weeks ago

My example above should work in .NET 9, maybe it doesn't work in .NET 8?

Back then @(AndroidPackagingOptionsExclude) was declared somewhere else?

jpobst commented 3 weeks ago

That's what I thought, but apparently it doesn't work in this case. Do you think maybe it was caused by the issue you are fixing in this PR and they will now be clearable without needed a target?

jonathanpeppers commented 3 weeks ago

/azp run

jonathanpeppers commented 3 weeks ago

Ok, there's an outage apparently:

image

jonathanpeppers commented 3 weeks ago

/azp run

azure-pipelines[bot] commented 3 weeks ago
Azure Pipelines successfully started running 1 pipeline(s).