Can't run a Xamarin App in iPhone Simulator from Visual Studio For Mac
Asked Answered
A

3

8

In short: I am unable to run my app in the iPhone Simulator. There is no "Play button" (the triangle), only a Debugger button (hammer):

enter image description here

As you can see above I have "Generic Simulator". When I click on it, there is no list of various iPhones/iPads to choose from: enter image description here

If I choose Android, I am able to run the app:

enter image description here

I have XCode installed. I ran XCode once. I also installed the Command Line tools. enter image description here

I created a new Xamarin Forms App: enter image description here enter image description here Here are my iOS build options: enter image description here

I am able to run the Simulator separately:

enter image description here

Creating an App in XCode and running in the Simulator works: enter image description here

info.plist: enter image description here

Prefrences -> SDK Locations -> Apple enter image description here

Build -> Configurations: enter image description here enter image description here

Here is the kicker though. If I run a Xamarin App on my Windows machine using the iPhone Simulator on the Mac, it works! enter image description here What do I need to do so I can run my app inside the Simulator vis Visual Studio for Mac?

Agreeable answered 4/4, 2021 at 7:39 Comment(7)
Change Deployment Target in the info.plist to lower version and check.Denaedenarius
Hi @Denaedenarius I've added an image of my info.plist. I don't see a Deployment TargetAgreeable
Minimum system version is called Deployment Target. Which you have set already 8.0. So, that should not be a problem. Check Apple SDK path is set properly (Preference -> SDK Location -> Apple). It should have green tick mark with Xcode version and SDK path location.Denaedenarius
It indeed has the checkmark and path location (I've added a screenshot to the Question)Agreeable
Please try this. Right click on the solution -> options -> Configurations -> Configuration manager -> ProjectName.iOS with Debug|iPhoneSimulator should be checked or if configuration "ProjectName.iOS with Debug|iPhoneSimulator" is not available then add this from General tab.Denaedenarius
There is "Configurations" under "Build" and under "Run". The one under "Run" Is emptyAgreeable
Yes, you need to add the simulator configuration. I have posted picture in my answer. Please check.Denaedenarius
D
4

Few options you can worth to check. @WorldOfBasti suggested options plus following.

  1. Configuration

Right click on the solution -> options -> Configurations -> Configuration manager -> ProjectName.iOS with Debug|iPhoneSimulator should be checked or if configuration "ProjectName.iOS with Debug|iPhoneSimulator" is not available then add this from General tab

enter image description here

  1. Apple SDK path

Check Apple SDK path is set properly (Preference -> SDK Location -> Apple). It should have green tick mark with Xcode version and SDK path location. enter image description here

  1. Minimum system version (Deployment Target)

Change Deployment Target to minimum version (ie, lower than your simulator version)

  1. Switch debug <-> release

Today I have also faced same issue which you are facing. I have switched debug to release, iOS to Android. Then reverted back to iOS and debug from the top device selection status bar. Then Simulator option was appearing. So, might be UI updated issue in Visual studio for mac. Please give a try.

enter image description here

Denaedenarius answered 5/4, 2021 at 0:40 Comment(4)
Thanks for all the effort but it just does not seem to work. Something must be wrong with this computer. I am going to try on a different one. I've added images of my Configurations. They look like yoursAgreeable
On the other computer everything worked immediately. So even though this computer was a clean install of the OS I think maybe because it is very old (2012 27-inch iMac) that can only run Catalina MacOS, then there are issues even though XCode works fine. I will give you the answer though since I'm sure this can be helpful to othersAgreeable
Yeah that sounds very strange. Maybe you can try to got to the technical support: visualstudio.microsoft.com/vs/support/macSagitta
I noticed this behavior after a recent update to VS-Mac. #3 did the trick for me.Mikiso
S
1

I assume that you tried the basics things like restarting your Mac, etc. So here are a few things, that might solve your problem:

  • Check your build configurations, here is a good video
  • Close VS for Mac, start Xcode and create a test project which you run on a simulator. If it works try again in VS for Mac
  • Close VS for Mac, goto Xcode -> Preferences -> Accounts and download the manual profiles of your developer account. Try again in VS for Mac
  • Clean your project: In VS for Mac, goto Build -> Clean All. Then Close VS for Mac, goto your project folder and delete in "yourprojectname" and "yourprojectname".iOS all bin and obj folders. Try again

If all of this doesn't work, I would try to reinstall it (if you have any important projects, make a backup):

  • Uninstall VS for Mac and Xcode
  • Install Xcode again from the App Store
  • Install Visual Studio for Mac

Hopefully it works..

Sagitta answered 4/4, 2021 at 11:21 Comment(1)
Thanks for your suggestions but none of them worked 😬. I watched James video and the build config looks okay (you can see the screenshot). I ran in XCode an app (added a screenshot). Clean All didn't change anything. Regarding reinstalling, I actually (prior to posting this question) reformatted the HD and reinstalled the OS to try to solve this issue, so this computer is stock + XCode + Visual StudioAgreeable
M
1

Looking at the Visual Studio for Mac logs, specifically the IDE log, I found this line ... 'The target name of simulated device could not be added because it's already cached'.

You are welcome to read through all of this ... but you may just want to go down to the Addendum 2 (final?) and see if that works for you ... it ends up being simpler and quicker than anything else I have found.

So, at first, I started clearing the cache with a 'xcrun simctl erase all' command from Terminal, and when I started Visual Studio for Mac I could run a Xamarin App, but launching the simulator took quite a bit of time.

So hare's something I found works that you might want to try ...

  • Close iOS Simulator on Mac (if any).
  • Close ALL copies of Visual Studio that are connected to the Mac ... either on the Mac itself or on another computer connected to the Mac (if any).
  • Start Visual Studio for Mac.
  • If you can't run a Xamarin App, Close Visual Studio for Mac.
  • Launch the Simulator manually (I have it in the Dock, so I just click it) ... wait for it to fully startup.
  • Now close the Simulator (from the Simulator menu).
  • Now restart Visual Studio for Mac.
  • If you still can't see the simulator devices to run on ... try the above steps one more time (this time you should only have to close Visual Studio for Mac followed by manually starting the Simulator, waiting for it to start, and then quitting the Simulator and finally restarting Visual Studio for Mac).

It still isn't great, but this has (so far) always worked for me. And the Simulator starts up substantially quicker then if I did a 'xcrun simctl erase all' command from Terminal.

Addendum: Most of the time the above works. But occasionally I still have to clear the cache from the Terminal with 'xcrun simctl erase all' command.

Also: I have also found (although maybe it's just my imagination) that clearing out the Visual Studio for Mac temporary .binlog files that are written in the 'T' folder will sometimes fix the problem (if you look at an IDE log from Visual Studio for Mac; right after the 'The target name of simulated device could not be added because it's already cached' message, you should see some .tmp files being created. The directory where they were created is the 'T' folder I'm talking about). I sometimes delete the tmp*.binlog and tmp*.tmp as a last ditch effort before using the 'xcrun simctl erase all' command to try to get back to where Visual Studio for Mac will see the iOS Simulator Devices.

Finally: This is really starting to feel like a bug in Visual Studio for Mac startup (or possibly during a iOS project load). The reason I say that is I can ALWAYS see the iOS Device list from Visual Studio for Windows (as long as I can connect to the Mac). In addition, I can leave Visual Studio for Mac running (even hidden) and test an app on the iOS Simulator from Windows, then, leaving the iOS Simulator Running on the Mac, run an App on Visual Studio for Mac. If there really were a 'caching issue' with the Simulator it seems to me I should have problems running anything on the Mac after using the iOS Simulator from Windows, but it always works. For now, I'm working on a single Xamarin Project on the Mac (and I don't use the Mac for anything else), So I just let Visual Studio for Mac 'open at login' (Dock setting) and automatically 'load previous solution on startup' (Visual Studio for Mac setting), hide Visual Studio for Mac (Dock Setting) and if I need it, Visual Studio for Mac is already loaded and able to see iOS Devices to run Apps on with a quick click on the Dock Icon.

Addendum 2 (final?): I have now found that if I just close a solution that I have open that shows 'Generic Simulator' and re-open it without exiting Visual Studio for Mac (sometimes I have to do it multiple times ... I think I've counted up to 5 times before it finally worked), it will start showing the device list and I can run the iOS app in the Simulator. I don't even have to close the Simulator if it's already running, which saves a bunch of time.

It still feels like a bug to me, I don't see why I would have to close/open a solution multiple times to get the iOS devices listed and be able to run an iOS app. What really gets me is if I reboot the Mac, don't open the Simulator and start Visual Studio for Mac, then open a solution, I still have to go through the close/re-open solution steps... sometimes more than once. The simulator is not set to auto start or anything like that. But, at least, it's getting simpler, and takes less time, to get to a point where I can run an iOS app.

Meyerbeer answered 7/7, 2021 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.