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

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

Conversation

jonathanpeppers
Copy link
Member

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:

  • is this Android?

  • is this the expected .NET framework version?

<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

…props`

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:

* is this Android?

* is this the expected .NET framework version?

`<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
Copy link
Contributor

jpobst commented Oct 28, 2024

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
Copy link
Member Author

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
Copy link
Member Author

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

Back then @(AndroidPackagingOptionsExclude) was declared somewhere else?

@jpobst
Copy link
Contributor

jpobst commented Oct 28, 2024

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
Copy link
Member Author

/azp run

@jonathanpeppers
Copy link
Member Author

Ok, there's an outage apparently:

image

@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor jonpryor merged commit 70948d5 into dotnet:main Nov 8, 2024
55 of 57 checks passed
jonathanpeppers added a commit that referenced this pull request Nov 8, 2024
…9463)

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:

  * Is this Android?

  * Is this the expected .NET framework version?

`<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][0].

[0]: https://github.com/dotnet/maui/blob/f269ef3de701043910c941bbbfcbdb7422cc245c/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.SingleProject.Before.targets#L10
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 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