Skip to content

Support for $(TargetFrameworks) per $(RuntimeIdentifier) (RID) #37830

Open
@jonathanpeppers

Description

@jonathanpeppers

Is your feature request related to a problem? Please describe.

Currently, Android projects build 4 architectures by default:

<TargetFramework>net9.0-android<TargetFramework>
<!-- these are implicit if you leave them blank -->
<RuntimeIdentifiers>android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>

We have custom MSBuild logic that "combines" the 4 architectures and emits a final Android package at the end. To make this work, we run an <MSBuild /> task per-RID that runs a subset of the dotnet publish MSBuild targets for trimming, Mono AOT compilation, etc.

It would be nice if the .NET SDK had built-in support for this, as it could be useful for several scenarios:

  • Android (as mentioned)
  • macOS or MacCatalyst, has similar logic as Android. Mac apps on the App Store should target x64 and arm64 currently.
  • I have a console app, I want to publish it with NativeAOT, single file, targeting N platforms.

Describe the solution you'd like

One solution, would be to make a new TargetFramework syntax, such as:

<TargetFrameworks>net9.0-android/android-arm;net9.0-android/android-arm64;net9.0-android/android-x86;net9.0-android/android-x64</TargetFrameworks>

The .NET SDK would handle running inner/outer builds with the <MSBuild/> task.

PROs

This would enable the Android & macOS/MacCatalyst workloads to rely on logic in the .NET SDK instead of inventing our own.

This also would be useful, in that new #if directives could exist like:

#if ARM || ARM64
    // Do some "arm"-y stuff
#elif X86 || X64
    // Do some macOS Intel or Android emu/Chromebook/WSA stuff
#endif

This would be useful on both macOS and Android.

CONs

  • We now run the C# compiler N times. Build performance concerns?

  • MAUI projects will have a combinatorial explosion of $(TargetFrameworks).

Additional context

This is related to:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions