dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

Dotnet: Multi-target projects require all 'TargetFrameworks' installed in order to build #34496

Open projectgoav opened 1 year ago

projectgoav commented 1 year ago

It was suggested I raise my query here via: https://github.com/xamarin/xamarin-macios/issues/18634

Describe the bug

I have the following csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net6.0;net6.0-ios</TargetFrameworks>
  </PropertyGroup>

</Project>

When I execute the following command on Windows, Mac or Linux:

dotnet build <csproj> --framework net6.0

the build errors due to missing iOS workload.

On windows & Mac, this is easily solved by installing the ios workload.

On Linux, it recommends I install the macos workload. Doing so then results in:

error NETSDK1178: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: Microsoft.iOS.Sdk.net6
error NETSDK1178: You may need to build the project on another operating system or architecture, or update the .NET SDK.

Why it this? I had assumed a multi-target project would only need the iOS workload installed when you specifcy --framework net6.0-ios?

Further technical details

Happens on both dotnet v6 & v7 running on Windows, Mac-x64 & Linux-x64 machines either via the command line or via Visual Studio 19, Visual Studio 22 (Windows & Mac)

baronfel commented 1 year ago

@projectgoav do you have an https://aka.ms/binlog that you could share here? I'm not super-clear on what happens when you have the same TFM with different 'platforms' - it's entirely possible that we're accidentally doing multitargeted builds in the SDK and we lack the ability to build the platform-less variant.

projectgoav commented 1 year ago

dotnet multitarget.zip

Please find attached:

Please let me know if I can provide any more information.

projectgoav commented 1 year ago

Any word on this?

bruno-garcia commented 1 year ago

I believe I'm hitting the same issue, on macOS. Clean checkout of https://github.com/getsentry/sentry-dotnet which has several projects multi targeting, including:

MAUI net6 and net6-android, ios etc: https://github.com/getsentry/sentry-dotnet/blob/2f11b3073e4169a60cc8143b8d5bd6016a3b826a/src/Sentry.Maui/Sentry.Maui.csproj#L9-L13 Core Sentry package with many targets: https://github.com/getsentry/sentry-dotnet/blob/2f11b3073e4169a60cc8143b8d5bd6016a3b826a/src/Sentry/Sentry.csproj#L11-L14

Change from latest SDK 7.0.1xx to 8.0.100-rc.1.23455.8. Not changing any target frameworks or anything:

/usr/local/share/dotnet/sdk/8.0.100-rc.1.23455.8/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1178: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: Microsoft.NETCore.App.Runtime.AOT.Cross.net6.ios-arm Microsoft.NETCore.App.Runtime.AOT.Cross.net6.ios-arm64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-arm64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-x64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-x86 [/Users/bruno/git/sentry-dotnet/src/Sentry.Bindings.Cocoa/Sentry.Bindings.Cocoa.csproj::TargetFramework=net6.0-ios]
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23455.8/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1178: You may need to build the project on another operating system or architecture, or update the .NET SDK. [/Users/bruno/git/sentry-dotnet/src/Sentry.Bindings.Cocoa/Sentry.Bindings.Cocoa.csproj::TargetFramework=net6.0-ios]
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23455.8/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1178: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: Microsoft.NETCore.App.Runtime.AOT.Cross.net6.ios-arm Microsoft.NETCore.App.Runtime.AOT.Cross.net6.ios-arm64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-arm64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-x64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-x86 [/Users/bruno/git/sentry-dotnet/src/Sentry.Maui/Sentry.Maui.csproj::TargetFramework=net6.0-ios]
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23455.8/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1178: You may need to build the project on another operating system or architecture, or update the .NET SDK. [/Users/bruno/git/sentry-dotnet/src/Sentry.Maui/Sentry.Maui.csproj::TargetFramework=net6.0-ios]
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23455.8/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1178: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: Microsoft.NETCore.App.Runtime.AOT.Cross.net6.ios-arm Microsoft.NETCore.App.Runtime.AOT.Cross.net6.ios-arm64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-arm64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-x64 Microsoft.NETCore.App.Runtime.AOT.Cross.net6.iossimulator-x86 [/Users/bruno/git/sentry-dotnet/src/Sentry/Sentry.csproj::TargetFramework=net6.0-ios]
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23455.8/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1178: You may need to build the project on another operating system or architecture, or update the .NET SDK. [/Users/bruno/git/sentry-dotnet/src/Sentry/Sentry.csproj::TargetFramework=net6.0-ios]

This happens on a mac (build output): https://github.com/getsentry/sentry-dotnet/actions/runs/6202867194/job/16842466816?pr=2622

On Linux, where we don't build the iOS targets, it doesn't.

HavenDV commented 1 year ago

Workaround: use dotnet build <csproj> --framework net6.0 -p:TargetFrameworks=net6.0