☰ Brand

Persian Programmer

Persian Programmer ×
Home About Us Services and Pricing Contact Us My Resume Co-worker

Build Xamarin apps with VS Code to M1 Macs, iPhones & Android

Build Xamarin apps with VS Code to M1 Macs, iPhones & Android

There have been numerous questions on different forums, of developers asking how to build Xamarin Apps using the terminal/CLI. The primary software/program used for Xamarin cross platform development is Microsoft’s Visual Studio. Visual Studio is classified as an Integrated Development Environment (IDE) that is used to build Xamarin apps. So, it has all the functionality you would need to build, debug and publish apps. This naturally makes Visual Studio bulky & slower than just building using CLI.

For decades now, software developers have preferred the use of lightweight text editors when possible because they are nifty and quick with changes, since a lot tasks don’t need the complex IDE. Microsoft’s Visual Studio Code is the most popular text editor among developers, with countless free extensions to enhance developer experience.

Note that the steps below do not support debugging, the iOS commands need to be done on a Mac, and the build will not work for iPhones and Macs if you have not correctly setup your Development Certificate and Provisioning profile in the Apple Developer portal (follow these steps to get temporary ones setup).

The First Prototype is an emerging Mobile App Design and Development consulting small business, specializing in Xamarin Forms and Native apps. Sign up on our website, and support us on social media, to be informed of our exciting new IslandLanding game on iOS & Android!

For all of these steps, you need to install and then open VS Code into the directory containing your Xamarin solution file. Then open the terminal by selecting Terminal in the toolbar->New Terminal. Restore nuget packages using the nuget restore command. Then follow the steps below depending on which platform you would like to build, and simply replace Sample with your project name:

Steps to Build & Deploy to Android with VS Code

  1. In your terminal, run this msbuild Sample.Android/Sample.Android.csproj /verbosity:normal /t:Rebuild /t:PackageForAndroid /t:SignAndroidPackage /p:Configuration=Debug
  2. Then, go to Sample.Android/bin/Debug to find the the signed APK file,
  3. Using ADB(Android Debug Bridge), install it to your device/emulator with this command adb install com.tfp.sample-Signed.apk, explained here.

Steps to Build & Deploy to iOS Simulator with VS Code

  1. In your terminal, run this msbuild Sample.iOS/Sample.iOS.csproj /verbosity:normal /t:Rebuild /p:Platform=iPhoneSimulator /p:Configuration=Debug
  2. Then, go to Sample.iOS/bin/iPhoneSimulator/Debug to find the Sample.iOS APP file,
  3. Simply drag and drop that file to your simulator to install it.

Steps to Build & Deploy to iPhone device with VS Code

  1. In your terminal, run this msbuild Sample.iOS/Sample.iOS.csproj /verbosity:normal /t:Rebuild /p:Platform=iPhone /p:Configuration=Debug
  2. Then, go to Sample.iOS/bin/iPhone/Debug to find the Sample.iOS APP file
  3. With your iPhone connected and unlocked, open Xcode -> Window ->Devices & Simulators ->Tap on the + sign and select the APP file.

Steps to Build & Install Xamarin app to Mac M1 with VS Code

  1. In your terminal, if you haven’t run it for iPhone above, run this msbuild Sample.iOS/Sample.iOS.csproj /verbosity:normal /t:Rebuild /p:Platform=iPhone /p:Configuration=Debug
  2. Then, go into the package contents of the app file using cd Sample.iOS/bin/iPhone/Debug/Sample.iOS.app.
  3. Finally, create the ipa using zip -r Blank.iOS.ipa ./ and simply double tap on it to install in to your MacOS Applications directory, and open.
 

Additional Considerations

  • If you are having problems with your iPhone Simulator build, you can open Visual Studio, and in the iOS project settings, set your Debug iOS Simulator Bundle Signing Identity and Provisioning Profile to Automatic.
  • If you’re having troubles with your iPhone/Mac M1 deployment, make sure that the installed Apple Developer certificate and Provisioning profiles correspond exactly as the Entitlements and Bundle identifier of the app inside your info.plist file.
  • Instead of /t:Rebuild, you can alternatively use /t:Build to speed up things even more

Sometimes in the pursuit of knowledge, you stumble upon other knowledge that’s more valuable than what you were initially looking for. A while ago I wrote an article on GitHub Actions but I didn’t find any other article taking it to the next level. I learnt these cool tricks during my research for the Advanced GitHub Actions article (coming soon), so I hope you are equally excited about them! Here’s a short video showing all of this in working:

0 comments

answer