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

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

Open
jonathanpeppers opened this issue Jan 8, 2024 · 3 comments
Open

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Jan 8, 2024

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:

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Workloads untriaged Request triage from a team member labels Jan 8, 2024
@baronfel baronfel added the needs team triage Requires a full team discussion label Jan 9, 2024
@marcpopMSFT
Copy link
Member

Nuget is looking into TFM aliasing that could potentially enable this. They are looking at allowing multiple identical underlying target frameworks in a single project which is what is needed for this. Then there would likely need SDK work to enable using aliases with rids.

CC @zivkan for visibility on an alias use case.

@marcpopMSFT marcpopMSFT added this to the 9.0.1xx milestone Jan 9, 2024
@marcpopMSFT marcpopMSFT removed untriaged Request triage from a team member needs team triage Requires a full team discussion labels Jan 9, 2024
@dsplaisted
Copy link
Member

Here is the issue tracking the NuGet work which would be the next step towards enabling this: NuGet/Home#12124

@jonathanpeppers
Copy link
Member Author

The part that seems tricky about this feature, do we really want a MAUI project to look like:

<TargetFrameworks>
  net9.0-android/android-arm;
  net9.0-android/android-arm64;
  net9.0-android/android-x64;
  net9.0-android/android-x86;
  net9.0-ios/iossimulator-arm64;
  net9.0-ios/ios-arm64;
  net9.0-maccatalyst/maccatalyst-arm64;
  net9.0-maccatalyst/maccatalyst-x64;
  net9.0-tizen;
  net9.0-windows10.0.19041.0;
</TargetFrameworks>

The property is so long now, it made me think to put each entry on its own line.

In the case of iOS, you would do debugging/development with the iOS simulator and Release/App Store builds are ios-arm64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants