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

Specifying both -f ... and -r ... to dotnet build fails to restore if multiple frameworks are present in the project file #21877

Open
rolfbjarne opened this issue Oct 8, 2021 · 37 comments

Comments

@rolfbjarne
Copy link
Member

Describe the bug

Repro:

$ dotnet new maui
$ dotnet build -f:net6.0-ios -r ios-arm64
Microsoft (R) Build Engine version 17.0.0-preview-21477-04+3a1e456fe for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
/usr/local/share/dotnet/packs/Microsoft.MacCatalyst.Sdk/15.0.101-preview.10.54/targets/Xamarin.Shared.Sdk.targets(1138,3): error : The RuntimeIdentifier 'ios-arm64' is invalid. [/Users/rolf/test/dotnet/maui/maui.csproj]

The problem is that it's trying to restore the net6.0-maccatalyst framework from the project file using the ios-arm64 RuntimeIdentifier, which fails, because ios-arm64 is not a valid RuntimeIdentifier for Mac Catalyst.

It seems that the implicit restore by "dotnet build" does not take into account the specified -f value (or takes into account the -r value when it shouldn't).

Binlog: msbuild.binlog.zip

Further technical details

dotnet --info
$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-rtm.21477.21
 Commit:    690faf288e

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-rtm.21477.21/

Host (useful for support):
  Version: 6.0.0-rtm.21477.8
  Commit:  a7e9f9fb23

.NET SDKs installed:
  2.0.3 [/usr/local/share/dotnet/sdk]
  2.1.504 [/usr/local/share/dotnet/sdk]
  2.1.700 [/usr/local/share/dotnet/sdk]
  2.1.810 [/usr/local/share/dotnet/sdk]
  2.2.107 [/usr/local/share/dotnet/sdk]
  2.2.203 [/usr/local/share/dotnet/sdk]
  2.2.204 [/usr/local/share/dotnet/sdk]
  3.0.100 [/usr/local/share/dotnet/sdk]
  3.1.100 [/usr/local/share/dotnet/sdk]
  3.1.200 [/usr/local/share/dotnet/sdk]
  3.1.201 [/usr/local/share/dotnet/sdk]
  3.1.402 [/usr/local/share/dotnet/sdk]
  5.0.100-dev [/usr/local/share/dotnet/sdk]
  5.0.100-preview.1.20155.7 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.3.20170.3 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.4.20212.3 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.4.20214.36 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.5.20223.3 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.5.20227.16 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.5.20256.10 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.5.20263.11 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.6.20265.2 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.6.20269.4 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.7.20307.3 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.7.20317.11 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.8.20359.11 [/usr/local/share/dotnet/sdk]
  5.0.100-rc.1.20411.10 [/usr/local/share/dotnet/sdk]
  5.0.100-rc.1.20414.5 [/usr/local/share/dotnet/sdk]
  5.0.100-rc.1.20426.3 [/usr/local/share/dotnet/sdk]
  5.0.100-rc.2.20459.1 [/usr/local/share/dotnet/sdk]
  5.0.100-rc.2.20480.7 [/usr/local/share/dotnet/sdk]
  5.0.100-rtm.20509.5 [/usr/local/share/dotnet/sdk]
  5.0.102 [/usr/local/share/dotnet/sdk]
  5.0.200 [/usr/local/share/dotnet/sdk]
  5.0.202 [/usr/local/share/dotnet/sdk]
  6.0.100-alpha.1.20554.10 [/usr/local/share/dotnet/sdk]
  6.0.100-alpha.1.20559.4 [/usr/local/share/dotnet/sdk]
  6.0.100-alpha.1.21060.3 [/usr/local/share/dotnet/sdk]
  6.0.100-alpha.1.21062.17 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.1.21081.5 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.1.21103.13 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.2.21114.3 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.2.21153.28 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.2.21155.3 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.3.21202.5 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.4.21215.1 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.4.21218.6 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.4.21226.14 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.4.21255.9 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.5.21302.13 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.5.21303.17 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.5.21308.63 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.6.21280.2 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.6.21308.62 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.6.21309.26 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.6.21328.1 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.7.21362.12 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.7.21364.4 [/usr/local/share/dotnet/sdk]
  6.0.100-rc.1.21405.1 [/usr/local/share/dotnet/sdk]
  6.0.100-rc.1.21458.1 [/usr/local/share/dotnet/sdk]
  6.0.100-rc.2.21420.30 [/usr/local/share/dotnet/sdk]
  6.0.100-rtm.21477.21 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.1.20124.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.3.20170.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.3.20170.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.4.20211.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.4.20214.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.5.20223.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.5.20227.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.5.20255.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.6.20265.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.6.20269.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.7.20307.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.7.20311.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-preview.8.20359.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.1.20405.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.1.20424.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.2.20458.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.2.20475.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rtm.20508.30 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-alpha.1.20526.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-alpha.1.21059.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-alpha.1.21062.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.1.21078.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.1.21103.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.2.21112.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.2.21125.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.2.21154.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.3.21201.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.4.21213.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.4.21222.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.4.21253.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.5.21217.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.5.21301.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.6.21277.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.6.21306.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.6.21325.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.7.21360.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.7.21363.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21404.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21419.24 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rtm.21477.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.22 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.1.20120.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.3.20169.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.4.20210.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.4.20214.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.5.20223.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.5.20227.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.5.20253.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.6.20263.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.6.20264.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.7.20306.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.7.20317.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-preview.8.20358.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20404.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20425.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.2.20454.25 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.2.20475.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rtm.20508.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-alpha.1.20553.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-alpha.1.20557.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-alpha.1.21059.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-alpha.1.21061.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.7.21360.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21403.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21420.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rtm.21477.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Request triage from a team member labels Oct 8, 2021
@jonathanpeppers
Copy link
Member

jonathanpeppers commented Feb 2, 2022

I found that restore is what causes this problem.

So you can workaround by doing something like:

$ dotnet new maui
$ dotnet restore
$ dotnet build -f net6.0-ios -r ios-arm64 --no-restore
$ dotnet build -f net6.0-android -r android-arm64 --no-restore

@rolfbjarne
Copy link
Member Author

Same thing happens with dotnet publish: xamarin/xamarin-macios#14015

@eerhardt
Copy link
Member

eerhardt commented Feb 2, 2022

IMO this is a critical scenario to fix. It is going to block / trip-up any developer who is trying to publish an iOS app.

$ dotnet new maui
$ dotnet publish -f net6.0-ios

Fails saying that you need to specify a RuntimeIdentifier. So then you do that:

$ dotnet publish -f net6.0-io -r ios-arm64

And that fails with this error: The RuntimeIdentifier 'ios-arm64' is invalid.

Now developers are stuck, and they have no idea what to do.

@marcpopMSFT @dsplaisted - is there anything we can do here?

@marcpopMSFT
Copy link
Member

I think this is similar to this item: #19487 (comment) Basically, TF specified on command line is not passed to the restore operation if it's not in the TargetFrameworks property of the project file. @dsplaisted we previously discussed options and should bring that up again.

@marcpopMSFT marcpopMSFT added the needs team triage Requires a full team discussion label Feb 2, 2022
@marcpopMSFT marcpopMSFT added this to the 6.0.3xx milestone Feb 2, 2022
@marcpopMSFT marcpopMSFT removed untriaged Request triage from a team member needs team triage Requires a full team discussion labels Feb 2, 2022
@dsplaisted
Copy link
Member

Possible solution: If the RuntimeIdentifier is specified on the command line, allow the TargetFramework from the command line to flow to the restore operation, since the RuntimeIdentifier being passed to restore will cause a re-restore anyway.

@eerhardt
Copy link
Member

Another developer has run into this issue: dotnet/runtime#65747.

I believe this is going to be hit by any Maui developer. Any chance this can get looked into for the Maui release? Is there a better command line people should be passing instead of saying -r RID?

@dsplaisted dsplaisted added the good first issue Issues that would be a good fit for someone new to the repository. Narrow in scope, well-defined. label Feb 23, 2022
@Mephisztoe
Copy link

IMO this is a critical scenario to fix. It is going to block / trip-up any developer who is trying to publish an iOS app.

$ dotnet new maui
$ dotnet publish -f net6.0-ios

Fails saying that you need to specify a RuntimeIdentifier. So then you do that:

$ dotnet publish -f net6.0-io -r ios-arm64

And that fails with this error: The RuntimeIdentifier 'ios-arm64' is invalid.

Now developers are stuck, and they have no idea what to do.

@marcpopMSFT @dsplaisted - is there anything we can do here?

I ran into thiswhen trying to set up an iOS Build Pipeline in Azure DevOps for my app. I was following the instructions found here and then experienced exactly these issues... is there at least a work around?

@jonathanpeppers
Copy link
Member

@Mephisztoe I think you should be able to run dotnet restore first, then use --no-restore when you run publish.

@Mephisztoe
Copy link

@Mephisztoe I think you should be able to run dotnet restore first, then use --no-restore when you run publish.

Tried that and didn't work.

Then it says:
Assets file '/Users/runner/work/1/s/.../obj/project.assets.json' doesn't have a target for 'net6.0-ios/ios-arm64'. Ensure that restore has run and that you have included 'net6.0-ios' in the TargetFrameworks for your project. You may also need to include 'ios-arm64' in your project's RuntimeIdentifiers. [/Users/runner/work/1/s/.../....csproj]

I did run a restore task before and my csproj of course includes this RID.

@jonathanpeppers
Copy link
Member

Does dotnet build work instead? dotnet publish doesn't really do anything extra on iOS/Android/etc., just copies files to another folder.

@eerhardt
Copy link
Member

eerhardt commented Mar 4, 2022

dotnet publish doesn't really do anything extra on iOS

I believe it creates the .ipa file, which build doesn’t.

@rolfbjarne
Copy link
Member Author

dotnet publish doesn't really do anything extra on iOS

I believe it creates the .ipa file, which build doesn’t.

Correct, but you can do that with build too:

dotnet build /p:BuildIpa=true

which is ultimately what publish does for iOS.

@Mephisztoe
Copy link

build instead of publish seems to work, btw. Thank's for this hint!

@dsplaisted
Copy link
Member

@nkolev @dotnet/nuget-team I'm not sure how to fix this, I think we need to have a discussion with the NuGet team. I thought that the issue had to do with the fact that we weren't forwarding the TargetFramework property to the restore operation. However, even if we do pass TargetFramework to the restore operation, NuGet will still see the TargetFrameworks property from the project file and try to restore for both target frameworks, and error out when one of them isn't compatible with the specified RuntimeIdentifier.

@steveisok
Copy link
Member

Possible solution: If the RuntimeIdentifier is specified on the command line, allow the TargetFramework from the command line to flow to the restore operation, since the RuntimeIdentifier being passed to restore will cause a re-restore anyway.

I was trying to publish an ios-arm64 app and was able to work around this by adding an ios-arm64 RuntimeIdentifier. That was enough for the restore to figure things out.

@otium99
Copy link

otium99 commented May 27, 2022

@otium99 no, I mean that you probably have <PlatformTarget>x64</PlatformTarget> in your csproj somewhere.

@rolfbjarne I don't. Neither the tag PlatformTarget nor the content x64.

ProjectFile.txt

@rolfbjarne
Copy link
Member Author

@otium99 no, I mean that you probably have <PlatformTarget>x64</PlatformTarget> in your csproj somewhere.

@rolfbjarne I don't. Neither the tag PlatformTarget nor the content x64.

ProjectFile.txt

That's strange. Can you get a binlog (build with the /bl flag: dotnet build /bl:msbuild.binlog ...) and upload the resulting msbuild.binlog file?

@otium99
Copy link

otium99 commented May 30, 2022

@rolfbjarne

Meanwhile I figured that when I change

<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>

to

<RuntimeIdentifiers>ios-arm64</RuntimeIdentifiers>

It starts compiling. But then I get stuck at "code signing key not found in keychain", which I am assuming is not related to the RuntimeIdentifier issue.

I've documented the whole process also here:
https://stackoverflow.com/questions/72399444/errors-with-dotnet-publish

@otium99
Copy link

otium99 commented May 30, 2022

@rolfbjarne I created a brand new maui project from the template, and it doesn't have this issue.

@rolfbjarne
Copy link
Member Author

@rolfbjarne msbuild.txt

The PlatformTarget property comes from the MonkeyFinder.csproj.user file, which the IDE creates.

If you're building from the command line, you should be able to just delete this file.

Meanwhile I figured that when I change

<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>

to

<RuntimeIdentifiers>ios-arm64</RuntimeIdentifiers>

It starts compiling. But then I get stuck at "code signing key not found in keychain", which I am assuming is not related to the RuntimeIdentifier issue.

Correct, you need to configure code signing. You can find more info here: https://docs.microsoft.com/en-us/xamarin/ios/get-started/installation/device-provisioning/

@Symbai
Copy link

Symbai commented Jun 5, 2022

I have exactly the same problem with The RuntimeIdentifier 'ios-arm64' is invalid. and found this issue. While I've added all the "workarounds" like removing catalyst from TargetFrameworks and deleting the csproj.user file, in the end it still failed with:

Recognized signature identity:

    Code Signing Key: "iPhone Distribution: xxx xxx (xxx)" (xxx)
    Provisioning Profile: "xxx" (xxx-xxx-xxx-xxx-xxx)
    Bundle Id: com.xxx
    App Id: xxx.com.xxx
   Completed execution of tool "xcrun" (exit code = 1).

  warning: ignoring unknown option: -z
  error: cannot parse the debug map for '/Users/xxx/Library/Caches/Xamarin/mtbs/builds/xxx/xxx
  xxx/bin/Release/net6.0-ios/ios-arm64/xxx.app/xxx
  xxx': No such file or directory

Just like everyone else:

<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>
<BuildIpa>False</BuildIpa>
<Configurations>Debug;Release;ARM64</Configurations>
<Platforms>AnyCPU;ARM64</Platforms>

  <PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <RuntimeIdentifiers>ios-arm64</RuntimeIdentifiers>
    <CodesignKey>iPhone Distribution: xxx xxx (xxx)</CodesignKey>
    <CodesignProvision>xxx</CodesignProvision>
    <ArchiveOnBuild>true</ArchiveOnBuild>
    <TcpPort>58181</TcpPort>
  </PropertyGroup>

And build with:
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:ServerAddress=192.168.178.54 /p:ServerUser=xxx /p:ServerPassword=xxx /p:TcpPort=58181 /p:ArchiveOnBuild=true /p:_DotNetRootRemoteDirectory=/Users/xxx/Library/Caches/Xamarin/XMA/SDKs/dotnet/

In the MS docs it sounds so simple to build using a macos host but in reality everything is just broken and fails with errors a normal user is not able to understand. Requires lots of workarounds and in the end it still doesn't work.

@otium99
Copy link

otium99 commented Jun 5, 2022

@Symbai I went through a myriad of errors as well.

Now I got it to work: https://stackoverflow.com/a/72511005/5909367

Maybe it helps you too.

In short, I guess this should be changed in your example: (Singular)
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>

and then
dotnet publish -f:net6.0-ios -c:Release

@Symbai
Copy link

Symbai commented Jun 5, 2022

@otium99:

Your original error is completely different one and your solution unfortunately that only generates a new error for me:

The resource file "C:\Users\xxx\source\repos\xxx\xxx\obj\project.a
ssets.json has no target for net6.0-ios/ios-arm64. Make sure the restore is running
t and that you have included "net6.0-ios" in the TargetFrameworks for your project. You may have to
e also include "ios-arm64" in your project's RuntimeIdentifiers.

So RuntimeIdentifiers (Plural) is correct in my case. With my posted settings I am at least able to "build" and sign but it fails on last step. I've now added the server IP, username and password etc. into the csproj file. And now I no longer get the error above instead something else when it tries to optimize the assembly size (linker aka AOT):

The assembly size is optimized, this can change the behavior of the app. Make sure to post-release testing. See https://aka.ms/dotnet-illink for information.

MessagingRemoteException: An error occurred on client Build while executing a reply for topic
 xvs/build/execute-task/xxx/f3ca8f6002fMergeAppBundles [C:\xxxs\xxx\source\repos\xxx\xxx\xxx.csproj]
C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.303\targets\Xamarin.Shared.Sdk.targets(366,3): error : 
AggregateException: One or more errors occurred. (The method or operation is not implemented.) [C:\xxxs\xxx\source\repos\xxx\xxx\xxx.csproj]
C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.303\targets\Xamarin.Shared.Sdk.targets(366,3): error : 
NotImplementedException: The method or operation is not implemented. [C:\xxxs\xxx\source\repos\xxx\xxx\xxx.csproj]

@otium99
Copy link

otium99 commented Jun 6, 2022

@Symbai Sorry to hear, that it doesn't work for you. So if I understand you correctly, you have now the same error as I had

Xamarin.Shared.Sdk.targets(366,3) MessagingRemoteException, AggregateException and NotImplementedException

but if you apply the solution that worked for me you get another error?

Today I had a new error popping up and I could solve it by deleting these folders, bin, obj and .vs

@Symbai
Copy link

Symbai commented Jun 6, 2022

I'm sorry but all of this is just bullsh... from changing plural to singular, deleting this file, this folder, adding and removing it from your csproj. And all of it only changes the error message you get, without you having a clue on what's going on. Trial and error until you succeed or until you notice you just wasted tons of hours. If you look at the official documentation on how to publish an iOS app, you see NONE of all of that is necessary. It says run this command and it should work. It does not. But it isn't my or your job to figure out whats the problem and how to solve it. I've already wasted enough hours on this. I just copied the whole project on my macbook and successfully compiled it on the mac with just a single command and now I'm done. I thought that with how old Xamarin is these basic things would be kinda stable and very well tested, now I wish that I'd have chosen something different if it wasn't too late for that.

@FarhadAmjad
Copy link

I got this working by building with the solution then use publish command from the main project directory.

@spouliot
Copy link

spouliot commented Aug 9, 2022

Considering IDE support is not yet available (and won't be for quite some time on macOS) this is an incredibly frustrating issue for developers working on cross-platform projects.

@dsplaisted can you assign someone (else, since @gkulin unassigned herself) on the issue. Thanks!

@marcpopMSFT marcpopMSFT removed the good first issue Issues that would be a good fit for someone new to the repository. Narrow in scope, well-defined. label Aug 9, 2022
@rolfbjarne
Copy link
Member Author

In the end we (xamarin/xamarin-macios) decided to remove the error to make things easier.

However, even though this works sometimes, when it fails, it fails in really confusing ways: see xamarin/xamarin-macios#16401, where restoring an android project fails with an error about a linux nuget package, but only if the macOS target framework is present in the project file...

Repro:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net6.0-android;net6.0-macos</TargetFrameworks>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
</Project>

Command:

$ dotnet build -f net6.0-android -c Release -p:RuntimeIdentifier=android-x64
MSBuild version 17.4.0-preview-22465-02+02b334e3a for .NET
  Determining projects to restore...
/Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj : error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-x64 with version (= 6.0.10)
/Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj : error NU1102:   - Found 5 version(s) in nuget.org [ Nearest version: 7.0.0-preview.5.22301.12 ]
/Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj : error NU1102:   - Found 0 version(s) in /usr/local/share/dotnet/library-packs
  Failed to restore /Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj (in 109 ms).

Incidentally you get the exact same error if restoring the macos target framework with the android runtime identifier:

$ dotnet build -f net6.0-macos -c Release -p:RuntimeIdentifier=android-x64
MSBuild version 17.4.0-preview-22465-02+02b334e3a for .NET
  Determining projects to restore...
/Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj : error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-x64 with version (= 6.0.10)
/Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj : error NU1102:   - Found 5 version(s) in nuget.org [ Nearest version: 7.0.0-preview.5.22301.12 ]
/Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj : error NU1102:   - Found 0 version(s) in /usr/local/share/dotnet/library-packs
  Failed to restore /Users/rolf/test/dotnet/issue-16401-a/testapp/testapp.Mobile/testapp.Mobile.csproj (in 109 ms).

which makes sense to fail (although the error message is more confusing than helpful).

@francoistanguay
Copy link

Hi,

Is there an update on this by any chance?

It affects quite a few of our customers and we'd love to know if there's anything we can do to help fix this

Thank you!.

@gameDNA-Helix
Copy link

Any update on this? This is a big issue.

@maonaoda
Copy link

maonaoda commented Jan 4, 2024

XXX.csproj
XXX.csproj.user


dotnet publish -f net8.0-ios -c Dev -p:ArchiveOnBuild=true -p:RuntimeIdentifier=ios-arm64

C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(288,5): error NETSDK
1032: RuntimeIdentifier プラットフォーム 'ios-arm64' と PlatformTarget 'x64' には互換性が必要です。 [XXX.csproj::TargetFramework=net8.0-ios]

I fixed it by deleting the XXX.csproj.user which was really strange.

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