xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.42k stars 507 forks source link

MAUI iOS: Command line to build maui ios app for iPhoneSimulator without CodeSigning key on Mac machine #20671

Closed PureWeen closed 4 weeks ago

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @muffadal53 on Friday, November 17, 2023 12:26:53 PM

Description

What is the command-line to build .net maui iOS release build on Mac machine for iPhoneSimulator without adding any CodeSigning key to keychain on mac device? I have tried with below command line but it is asking for valid Code signing key which I think should not be required for iPhone simulator:

dotnet build maui.csproj --configuration Release --no-restore -f net7.0-ios /p:verbosity=quiet /p:Platform="iPhoneSimulator"

I am getting following error:

No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com/.

Awaiting help on this. Thanks in advance.

Steps to Reproduce

What is the command-line to build .net maui iOS release build on Mac machine for iPhoneSimulator without adding any CodeSigning key to keychain on mac device? I have tried with below command line but it is asking for valid Code signing key which I think should not be required for iPhone simulator:

dotnet build maui.csproj --configuration Release --no-restore -f net7.0-ios /p:verbosity=quiet /p:Platform="iPhoneSimulator"

I am getting following error:

No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com/.

I am not able to find any relevant information in MAUI documentation.

Awaiting help on this. Thanks in advance.

Link to public reproduction project repository

N/A

Version with bug

7.0.101

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS16

Did you find any workaround?

N/A

Relevant log output

No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com/.
PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @mattleibow on Friday, November 17, 2023 10:17:21 PM

@rolfbjarne is there a change in the requirement for a signing key? This is a Release build it seems.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @mattleibow on Friday, November 17, 2023 10:17:39 PM

@muffadal53 does it build in Debug at all?

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @ghost on Friday, November 17, 2023 10:17:47 PM

Hi @muffadal53. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @muffadal53 on Saturday, November 18, 2023 4:15:29 AM

@muffadal53 does it build in Debug at all?

@mattleibow : I checked with Debug build it is the same thing that it needs code signing key. My use case is to build in Release as part of GitLab pipeline without codesigning key without generating .ipa file because generating the ".ipa" would be part of different Deployment job. And, even if I provide the code signing key in the .net maui dotnet build command it asks me for codesigning credentials on my Mac machine with a dialog which I don't want to have while building it as part of pipeline job. So, how can we avoid this part and let it do this part automatically.

In Xamarin forms this was possible without code signing key for iPhoneSimulator by following command:

msbuild ${APP_PROJECT_DIR}/${EXE_PROJECT_NAME} /p:Configuration="Release" /p:verbosity=quiet /p:Platform="iPhoneSimulator"

Where the "APP_PROJECT_DIR" is the project directory path and "EXE_PROJECT_NAME" is the project name of iOS project. So, is there something similar in .Net MAUI?

Awaiting your reply. Thanks.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @xanril on Sunday, November 19, 2023 10:26:39 AM

Try adding a runtime identifier as one of the build params -r iossimulator-x64 or -r iossimulator-arm64

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @rolfbjarne on Monday, November 20, 2023 6:00:00 AM

Try adding a runtime identifier as one of the build params -r iossimulator-x64 or -r iossimulator-arm64

Correct, this is how you build for the simulator. If this doesn't work, please add -bl:msbuild.binlog to the command line, and attach the resulting msbuild.binlog file.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @muffadal53 on Monday, November 20, 2023 6:16:47 AM

@xanril and @rolfbjarne : I tried as per the inputs from @xanril as per following command and and I am getting following warning and error on the pipeline output:

  1. Updated command line:

$ dotnet build ${APP_PROJECT_DIR} --configuration Release --no-restore -f net7.0-ios -p:verbosity=quiet -r iossimulator-arm64 -p:Platform="iPhoneSimulator"

  1. Warning: 

    ` warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used.`

  2. Error:

  `project doesn't have a target for 'net7.0-ios/iossimulator-arm64'. Ensure that restore has run and that you have included 
   'net7.0-ios' in the TargetFrameworks for your project. You may also need to include 'iossimulator-arm64' in your project's 
    RuntimeIdentifiers`

So, what is this error and how to resolve this?

Thanks.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @rolfbjarne on Monday, November 20, 2023 6:41:51 AM

Try removing --no-restore from the command line, that should fix the error.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @muffadal53 on Monday, November 20, 2023 7:04:58 AM

@rolfbjarne : Few queries on your input of removing "--no-restore" . What was that error about? and if I am doing a dotnet restore command like dotnet restore $SOLUTION_FILE --configfile nuget.config --verbosity quiet before the build then why what is wrong in adding "--no-restore" to the build commandline?

And FYI.. that earlier error is gone and I am getting below series of errors:

So, do we need this part "Optimizing assemblies for size. This process might take a while." for just building with iPhoneSimulator and how can we disable this or fix this errors?

Thanks.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @rolfbjarne on Monday, November 20, 2023 7:25:49 AM

Few queries on your input of removing "--no-restore" . What was that error about?

I'd need binlogs to confirm, but this is likely what happened:

  1. You ran dotnet restore $SOLUTION_FILE --configfile nuget.config --verbosity quiet. This restored the solution using the default runtime identifier(s), which may not have included iossimulator-arm64.
  2. You can dotnet build --no-restore -r iossimulator-arm64, and the build complained that you didn't restore using iossimulator-arm64.

It might work if you do dotnet restore -r iossimulator-arm64 ... in step 1 instead.

And FYI.. that earlier error is gone and I am getting below series of errors:

clang: error: linker command failed with exit code 1 (use -v to see invocation) error : clang++ exited with code 1: error : ld: warning: ignoring duplicate libraries.. error : ld: building for 'iOS-simulator', but linking in object file.. error : clang: error: linker command failed with exit code 1

Once again a binlog would confirm, but I'm guessing you're including a NuGet or native library that doesn't contain native bits for iossimulator-arm64. You might have more luck using iossimulator-x64 instead.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @muffadal53 on Monday, November 20, 2023 11:44:34 AM

@rolfbjarne: The iossimulator-x64 input seems to work for me. So, below is the actual commands which I am using are as below to restore and build .Net MAUI iOS without installing any Apple distribution certificate in Mac OS keychain:

`dotnet restore -r iossimulator-x64 $SOLUTION_FILE --configfile nuget.config --verbosity quiet

dotnet build ${APP_PROJECT_DIR} --configuration Release --no-restore -f net7.0-ios -r iossimulator-x64 -p:Platform="iPhoneSimulator" -p:verbosity=quiet`

So, are the above commands correct? And as I was struggling to find any documentation or any article on above details, can you please point me to detail documentation on this topic of command line and if not then I suggest that Microsoft to create one so that it will be helpful for the Developers working with command line for build pipelines other than Microsoft Azure.

Thanks.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @rolfbjarne on Monday, November 20, 2023 1:13:47 PM

Personally I would just do this:

dotnet build path/to/project.csproj -f net7.0-ios -r iossimulator-x64

Important points:

Building and running from the command line is documented here: https://learn.microsoft.com/en-us/dotnet/maui/ios/cli?view=net-maui-8.0

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @muffadal53 on Monday, November 20, 2023 2:48:44 PM

Personally I would just do this:

dotnet build path/to/project.csproj -f net7.0-ios -r iossimulator-x64

Important points:

  • The default runtime identifier is iossimulator-x64 (on an x64 machine) or iossimulator-arm64 (on an arm64 machine), so I'm assuming there's a RuntimeIdentifier property in your csproj setting it to ios-arm64, and that's why you need to override when building for simulator on the command line.
  • We don't use the Platform property, but your csproj might contain logic that depends on it, so I'm unsure whether you can just remove it or not.
  • Building simulator builds for the Release configuration is not very typical, any particular reason you're doing it?
  • Also restoring and building separately is not necessary, dotnet build will automatically restore if need be.

Building and running from the command line is documented here: https://learn.microsoft.com/en-us/dotnet/maui/ios/cli?view=net-maui-8.0

@rolfbjarne: Please find my comments to your points and queries below:

And regarding the documentation part I am not convinced because it no where mentions the command line parameter of -r iossimulator-x64 if we need to build without any code signing key/ Apple distribution certificate. And the errors we might get with the build like I faced and explanation on how to fix it with different command line options.

Thanks.

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @ryanryanorient on Thursday, January 18, 2024 12:39:09 AM

Whether things are progressing or not, I would also like to see the IPA built directly without using code signing

PureWeen commented 1 month ago

Issue moved from dotnet/maui#18836


From @rolfbjarne on Monday, January 22, 2024 4:07:30 PM

Whether things are progressing or not, I would also like to see the IPA built directly without using code signing

Setting the EnableCodeSigning property to false might do it (i.e. passing /p:EnableCodeSigning=false if building on the command line).

rolfbjarne commented 4 weeks ago

And regarding the documentation part I am not convinced because it no where mentions the command line parameter of -r iossimulator-x64 if we need to build without any code signing key/ Apple distribution certificate.

That's because that indirectly comes from your own project.

You have this:

<PropertyGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
   <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>

which means that unless you set RuntimeIdentifier from the command line, you're building for device.

And when you build for device, you need a signing certificate.