Are There Detailed Step-By-Step Instructions for Setting up Xcode & Visual Studio .NET for Xamarin.Ios Storyboard Projects?

huangapple go评论136阅读模式
英文:

Are There Detailed Step-By-Step Instructions for Setting up Xcode & Visual Studio .NET for Xamarin.Ios Storyboard Projects?

问题

我被要求修改并协助分发一个Xamarin .NET项目。我有源代码库,但我是一名Windows开发人员,一直以来都不太了解苹果技术,应用的原开发人员已经离职,不愿提供支持或帮助。这是为一个小型非营利组织而做的项目,所以他们对顾问的预算有限。

这个项目似乎可以正常构建,但当涉及到与Mac配对的部分时,我的Windows开发机连接上后经常断开。MacBook上已安装了Xcode和Visual Studio,但除了连接苹果帐户和构建了一些可能或可能没有正确完成的关键链访问方面,没有做太多其他事情。我不知道苹果软件是如何配置的或需要什么,大多数Xamarin文档表明,Windows .NET环境将自动与配对的苹果机器通信以满足其需求。

嗯,看来情况并非如此。似乎有很多需要弥补的空白。例如,这是一个针对iPad进行移动数据输入并在返回到受保护网络时将数据合并到客户/服务器应用程序的应用程序。但在构建项目时,没有iPad的模拟器,只有iPhone,尽管Xcode显示有iPad的模拟器。

当我在Visual Studio 2022中时,以下情况可以观察到:

  1. 与Mac配对的行为不稳定。有时可以成功连接,有时可能需要尝试2或3次才能连接上。然后一旦成功连接,尝试在调试模式下运行会产生一个晚期阶段的构建错误。有时这是由于Mac的断开连接引起的,有时是与代码签名相关的模糊错误。

  2. 我尝试了项目属性中的各种iOS包签名选项。自动配置失败,手动配置也失败。我按照在Mac上设置证书的说明来做,但对于我来说这都有点神秘,不清楚需要什么。

  3. 它总是在最后一个阶段失败,也就是当我选择调试或不调试运行时。它只显示iPhone和iPhone模拟器的选项。我成功地让我的iPad显示为一个输出设备,通过在Xcode中首先注册它,但与MacBook的通信似乎由于某种原因而失败。

有办法将这些问题解决吗?我曾认为有了源代码,重建开发环境并生成IPA文件不会很困难。现在我不太确定,因为有太多需要解决的变量。此外,这是在近3年内开发并且几乎没有修改的代码,因此在那段时间里,操作系统和SDK版本已经有了很大的发展。

是否有相关的文档或有人能够为我提供如何解决这个问题的简明说明?非常感谢...我原本期望一旦我将MacBook与Windows .NET开发环境配对,并安装了Xcode和Visual Studio for Mac,一切就会如期编译然后运行。似乎没有编译错误,但确实存在晚期绑定错误或其他阻止我开发完整可用的可执行文件的问题。

英文:

I have been tasked with making modifications and assisting with the distribution of an Xamarin .NET project. I have the source code repository, but I am a Windows Developer and have always been uncomfortable trying to understand Apple technologies. The person who developed the application has moved on and has no interest in providing support or assistance. It is for a small non-profit organization, so they have a limited budget for consultants.

The project seems to build fine, but when we get to the Pair to Mac portion of the puzzle, my Windows Development machine connects, but then frequently disconnects. The MacBook has Xcode and Visual Studio installed on it, but not much else has been done on it other than hook in the Apple accounts and build some keychain access stuff that may, or may not, have been done correctly. I have no idea how the Apple software was configured or what needs to be present there, most of the Xamarin documentation indicates that the Windows .NET environment will communicate it's needs to the paired Apple machine and it's all done auto-magically.

Well, that seems to not be the case. There seems to be a lot of gaps that I need to fill. For exammple, its an app that targets iPads for mobile data entry and then merging data back into the client/server application upon return to the secured network. When I build the project, there is no simulator for iPad, only iPhone, even though Xcode shows its got simulators for iPad.

When I am in Visual Studio 2022 the following can be observed:

  1. The Pair to Mac behavior is inconsistent. Sometimes it connects just fine, other times it may take 2 or 3 times to connect. Then once you connect successfully, trying to run in debug produces a late stage build error. Sometimes this is due to a disconnect of the Mac, other times its an obscure error about code signing.

  2. I have tried all sorts of variations on the iOS Bundle Signing entries within the project's properties. Automatic Provisioning fails, Manual Provisioning fails. I have followed instructions to set up a certificate on the Mac, but it is all a bit of a mystery to me what is needed here.

  3. It always fails at the latest stage which is when I choose to Debug or run without debugging. It only shows options for iPhone and iPhone Simulator. I did manage to get my iPad to show up as a device for output by registering it in Xcode first, but this communication with the MacBook seems to be failing for whatever reason.

Is there any way to put these pieces together? I had thought that with the source code, it would not be difficult to recreate a development environment and reach a point where we had an IPA file for distribution. Now I'm not so sure because there are so many variables to address. Also, this is code that was developed and largely untouched for almost 3 years, so the OS and SDK versions have advanced greatly in that period of time.

Does any documentation exist or would anyone be able to give me some concise instructions on how to make it right? TIA...

I was expecting that once I had the MacBook paired to the Windows .NET Development environment and had installed Xcode and Visual Studio for Mac, that things would compile then run as expected. There does not seem to be compilation errors, but there are definitely late stage binding errors or something that keeps me from developing a complete and usable executable.

答案1

得分: 0

根据ToolmakerSteve的说法:

> Mac-VS配对存在问题。使用在线源代码存储库,比如GitHub。从电脑上传代码,然后在Mac上下载它。在VS Mac上进行构建和iOS模拟器启动。幸运的话,您可以将显示器、鼠标和键盘移动到Mac上,这样就不需要新设备。

英文:

According to ToolmakerSteve:

> Mac-VS pairing is problematic. Use an online source repository, such
> as GitHub. Upload the code from the pc; download it to the mac. Do the
> builds & iOS Simulator launching there, in VS mac. With luck, you can
> move the monitor, mouse, keyboard to the mac, so don't need new
> equipment.

答案2

得分: 0

如果其他人遇到了这个问题,以下是最终让我理解并使事情对我起作用的原因,但你的情况可能不同。

当我查看在Mac上使用Visual Studio构建的项目时,它显示目标是iPad Pro(第六代)。这并不在我在Visual Studio(Windows)中可用的模拟器列表中,所以每次我尝试调试它时,Visual Studio都会显示“找不到设备”并停止,这是有道理的。

最终,在长时间的搜索后,我在GitHub上找到了一个最新的帖子:

https://github.com/xamarin/xamarin-macios/issues/17561

这篇帖子帮助了我。尽管我对Mac的了解非常有限,但我成功卸载了Xcode 14.3并降级到Xcode 14.2。我曾经读到xamarin.ios-16.4.0.3是正确的版本,但当我连接到MacBook时,它说我必须使用Xamarin.iOS和Xamarin.Mac SDK版本16.2.0.5,终于成功了!iPad现在在iPhone模拟器的设备列表中!

证书和配置文件是手动配置的。这是另一个需要理解如何上传/下载、双击它们、复制到Windows的过程:

构建用于开发的证书和密钥链

在MacBook上登录,启动Safari并使用您的开发人员凭据登录Apple Developer网站。

生成证书签名请求(CSR):在您的Mac上,打开Keychain Access(位于Applications文件夹内的Utilities文件夹中)。从Keychain Access菜单中,选择“Certificate Assistant” > “从证书颁发机构请求证书”。填写您的电子邮件地址,并选择“保存到磁盘”。这将生成一个CSR文件,我一直保存在Downloads/Certificate Files中。

请求开发证书:使用与您的开发者帐户关联的Apple ID登录到Apple Developer Account网站(developer.apple.com)。导航到Certificates, Identifiers & Profiles部分。在“Certificates”下,单击“+”按钮创建新证书。选择“iOS App Development”选项,上传上一步生成的CSR文件。

现在您将进入一个屏幕,显示您的证书名称、证书类型、过期日期等信息。单击“下载”,将.cer文件保存到Downloads文件夹中。打开该文件夹,双击“ios_development.cer”文件。这将在MacBook上安装证书,并将其添加到Keychain Access中。

创建一个配置文件:我创建了一个名为Dev Provisioning Profile的配置文件。它可以进行编辑以添加更多的用户或设备,但我认为需要一个单独的分发配置文件。这里也有一个下载按钮,所以在MacBook上,我下载然后双击下载的文件。

在Xcode中,在帐户区域,单击“管理证书”按钮时提供了大量信息。请注意,MacBook当前连接到我的帐户和主要的<您的公司名称>帐户。

在获得开发证书并将其安装到Mac上之后,您需要导出相应的私钥(.p12文件)并将其传输到Windows开发机器。这是在使用Xamarin.iOS项目时,在Windows上设置代码签名时所必需的。

要从Mac上导出私钥(.p12文件),请按照以下步骤操作:

在您的Mac上打开Keychain Access应用程序。您可以在Applications文件夹中的Utilities文件夹中找到它。

在Keychain Access应用程序中,从侧边栏中选择“Certificates”类别。

在列表中找到您的开发证书,并展开以显示相关的私钥。

在证书-私钥对上右键单击,然后从上下文菜单中选择“导出...”。

选择Mac上保存导出文件的位置,并为文件提供一个名称(例如,certificate.p12)。

在导出选项中,为导出文件选择一个密码。在将私钥导入Windows机器时,将需要此密码。

单击“保存”以将私钥导出为.p12文件。
一旦从Mac中导出了.p12文件,您可以使用USB驱动器、电子邮件、云存储或其他首选方法将其传输到Windows开发机器。

在Windows机器上,您可以将.p12文件导入证书存储库,和/或从Visual Studio -> Tools -> Xamarin -> Apple Accounts中拉取它。如果进入此区域,选择<您的公司Apple账户名称>,它会弹出一个新窗口,您可以在其中导入证书。那里还有一个按钮可以下载所有配置文件,当您创建或更改配置文件时,您应该进行下载。

在开发机器上的Visual Studio中,您还需要打开项目属性页。在iOS Bundle Signing部分,您需要输入正确的证书和配置文件。如果您想要的证书和配置文件不在列表中,请确保您已成功完成前面的步骤。

英文:

If anybody else runs into this, here's what finally caused me to catch on and get things working for me, YMMV.

When I looked at the the project that was built in Visual Studio on the Mac, it said that the target was iPad Pro (6th Generation). This was not on my list of simulators available in Visual Studio (Windows), so every time I went to debug it, Visual Studio said "Device not found" and stopped, which makes sense.

Finally, after hours and hours of searching, I found a recent post on Github:

https://github.com/xamarin/xamarin-macios/issues/17561

This post got me over the line. Although I know very little about Mac stuff, I was able to uninstall Xcode 14.3 and downgrade to Xcode 14.2. I had read that xamarin.ios-16.4.0.3 was the proper version, but when I connected to the MacBook, it said I had to use Xamarin.iOS and Xamarin.Mac SDK version 16.2.0.5 , IT FINALLY WORKED! The iPads are now in the device list for iPhoneSimulators!

The certificates and provisioning profiles are configured manually. That was another exercise in understanding how to upload/download, double click them, copy them to Windows. Here are the notes I've made about this process. More for my own reference since it seemed a little bit laborious:

Building Certificates & Keychains for Development
While logged into the MacBook, start Safari and log into the Apple Developer website using your developer credentials.

Generate a Certificate Signing Request (CSR): On your Mac, open Keychain Access (located in the Utilities folder within the Applications folder). From the Keychain Access menu, choose "Certificate Assistant" > "Request a Certificate From a Certificate Authority." Fill in your email address and choose "Saved to disk." This will generate a CSR file which I have been saving in Downloads/Certificate Files.

Request a Development Certificate: Sign in to the Apple Developer Account website (developer.apple.com) using the Apple ID associated with your developer account. Navigate to the Certificates, Identifiers & Profiles section. Under "Certificates," click on the "+" button to create a new certificate. Select the "iOS App Development" option, upload the CSR file generated in the previous step.

Now you are taken to a screen that displays your Certificate Name, Certificate Type, Expiration Date, etc. Click on Download, which will save the .cer file into the Downloads folder. Open up that folder and double click on the “ios_development.cer” file. This installs the certificate on the MacBook as well as adding it to the Keychain Access.

Create a Provisioning Profile: I have created a provisioning profile called Dev Provisioning Profile. It can be edited to add more users or devices, but I think a separate distribution provisioning profile is required. There is a Download button here as well, so on the MacBook, I downloaded then double-clicked on the downloaded file.

Within Xcode, in the Accounts area, there is a lot of information available when you click on the Manage Certificates button. Note that the MacBook is currently hooked to my account and the main <your company here> account.

After obtaining a development certificate and installing it on your Mac, you will need to export the corresponding private key (.p12 file) and transfer it to your Windows development machine. This is necessary to set up code signing in Visual Studio on Windows when working with Xamarin.iOS projects.
To export the private key (.p12 file) from your Mac, follow these steps:

Open the Keychain Access application on your Mac. You can find it in the Utilities folder within the Applications folder.

In the Keychain Access app, select the &quot;Certificates&quot; category from the sidebar.

Locate your development certificate in the list and expand it to show the associated private key.

Right-click on the certificate-private key pair and select &quot;Export...&quot; from the context menu.

Choose a location on your Mac to save the exported file and provide a name for the file (e.g., certificate.p12).

In the export options, choose a password for the exported file. This password will be required when importing the private key on your Windows machine.

Click &quot;Save&quot; to export the private key as a .p12 file.
Once you have the .p12 file exported from your Mac, you can transfer it to your Windows development machine using a USB drive, email, cloud storage, or any other preferred method.

On your Windows machine, you can then import the .p12 file into the certificate store and/or pull it in from the Visual Studio -> Tools -> Xamarin -> Apple Accounts. If you go to this area, select <your company Apple account here> and it pops up a new window where you can Import Certificates. There is also a button there to Download All Profiles, which you should probably do when you create or change a provisioning profile.

In Visual Studio on the development machine, you will also want to open up the project properties page. In the iOS Bundle Signing section you need to enter the correct certificate and provisioning profile. If the ones you want aren’t on the list, make sure you have completed the previous step(s) successfully.
1

huangapple
  • 本文由 发表于 2023年6月8日 23:26:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定