After the deprecation of the Visual Studio for Mac stack and the Xamarin Steps on Bitrise, there is a way to keep building Xamarin projects on Bitrise. Please note that this method is not guaranteed to work for all Xamarin projects and Bitrise will not officially support these projects anymore, but it might help Xamarin users until the official MAUI release.
Strategy
Ideally, the migration from the Visual Studio for Mac Stack should be easy and straightforward. The source code of the Xamarin steps will be available after the deprecation. Therefore, they can still be used by importing the source code directly in the bitrise.yml file (read the details here).
The Visual Studio for Mac Stack is based on an Xcode stack with Visual Studio for Mac and other related tooling installed. Our strategy will be to start from an Xcode stack and install all the tooling for building a Xamarin project.
Migration Setup
We wanted to avoid having to install the whole Visual Studio for Mac from the UI. This is why we focused on two commands that are used in the Xamarin steps: msbuild and nuget. We changed a 'Xamarin' project to be of type 'Other' so that we can choose from the standard Xcode Stacks and we copied the Xamarin build workflow. We selected the standard Xcode 12.5 stack.
After several attempts to configure the tools independently, from the command line, by installing dotnet and Mono, we were getting blocked by the required Xamarin dependencies. Then we noticed that everything that was needed to build the project was in 4 frameworks in the /Library/Frameworks directory.
Xamarin as 4 Frameworks
Our first successful attempt to build a Xamarin project on a standard Xcode stack was by downloading the following 4 frameworks
1. Mono.framework
2. Xamarin.iOS.framework
3. Xamarin.Android.framework
4. Xamarin.Mac.framework
from the Visual Studio for Mac Stack and copying them to /Library/Frameworks directory of the Xcode 12.5 Stack in a Script Step. This was sufficient to keep building.
In our experiment, we published the frameworks as a Bitrise artifact, and then we used the Bitrise API to download it. The downloading took about 2 minutes of building time. The size of the frameworks was about 1.7Gb.
Install with Homebrew
We shared the frameworks method with the community and we received some good feedback. If we could install the frameworks from the official sources, we could avoid storing them in external file storage and we could also install newer versions of Xamarin. We ended up using Homebrew Cask. We used this script from a Script Step.
It took 5.7 minutes to install the tooling.
Both ways can be used depending on whether the goal is to build fast or to be flexible with the versions. Once we’re certain that the versions won’t change, we can possibly save the frameworks to external file storage and get the best of both methods.
MAUI
MAUI is the future of Xamarin. Find more about it here.