Building Xamarin.iOS projects via Team Foundation Server

Update 2

Starting with Xamarin 3.5, thanks to the new "Unified Build" feature, if the Mac build host is available and properly paired, the Build target alone will run the remote build step in addition to the local build step.

Tested on 2 October 2014, with:

Steps to build a Xamarin.iOS project on the command line in Windows

  1. Pair to the build host via Visual Studio. This will cache the pairing information (the PIN and the server address) in %LOCALAPPDATA%\Xamarin\MonoTouch.

  2. Quit Visual Studio so that it won't conflict with the command line build.

  3. Run a command line build:

    msbuild HelloWorld1\HelloWorld1.csproj /t:Build

Building an IPA

Additional example for step 3, to build an Ad-Hoc IPA:

msbuild HelloWorld1\HelloWorld1.csproj /t:Build /p:Configuration=Ad-Hoc;Platform=iPhone

Update 1

Starting in Xamarin 3.1 (tested on 3.1.228) it's no longer necessary to specify the BSAT, HttpPort, or ServerAddress parameters when running the _RemoteBuild target on the command line. The "MonoTouchBuildNative_SayHello" task has been updated so that it finds these values automatically during a command line or TFS build.

Tested on 23 July 2014, with:

Steps to build a Xamarin.iOS project on the command line in Windows

  1. Pair to the build host via Visual Studio. This will cache the pairing information (the PIN and the server address) in %LOCALAPPDATA%\Xamarin\MonoTouch.

  2. Quit Visual Studio so that it won't conflict with the command line build.

  3. Run a command line build:

    msbuild HelloWorld1\HelloWorld1.csproj /t:Build;_RemoteBuild
      

There is no need to use Visual Studio to re-pair after rebooting.


Steps for older versions of Xamarin

Tested on 30 April 2014, with:

The process of building iOS projects via TFS is still tricky because every time you disconnect and reconnect to the build host, the HttpPort and BSAT can change. Also, the TFS build agent cannot perform this pairing, so TFS must reuse Visual Studio's connection. As a result, it's necessary to leave Visual Studio connected to the build host to preserve the HttpPort and BSAT. That said, as long as you keep VS paired to the build host by leaving any Xamarin.iOS project open, I've found that you can then build that project or any other Xamarin.iOS project you like.

As mentioned on [1], further improvements to the TFS build scenario are still planned or in progress. It's also likely that the steps I list below will stop working or need updates as the _RemoteBuild target changes in future releases.
[1] https://bugzilla.xamarin.com/show_bug.cgi?id=17748

Here are the steps I followed. In my case, the repairing in steps 3-5 was important during the first run-through. After that, as long as VS was paired, I was able to build via TFS too.

Project setup and connection information

  1. Install TFS (tested with TFS 2013 Trial).

  2. Create a new HelloWorld1 Xamarin.iOS project in a Team Project. Also be sure to set the Application Name and Identifier to avoid build errors later. Then "Check In" the project to the source control.

  3. Quit Visual Studio, and "Unpair" the Xamarin.iOS Build Host App.

  4. Restart Visual Studio, and open the HelloWorld1 project.

  5. Click "Pair" in the Xamarin.iOS Build Host App, and enter the PIN in Visual Studio.

  6. Enable diagnostic build output verbosity [2].
    [2] http://msdn.microsoft.com/en-us/library/jj651643.aspx

  7. Build the project once using the "Start" button, and then stop debugging.

  8. Find the "MonoTouchBuildNative_SayHello" task in the build output, and copy down the values of the following "Task Parameters" :

Build Definition

  1. Create a new Build Definition.

  2. Set the "Build Defaults -> Staging Location" to "This build does not copy output files to a drop folder".

  3. Set "Process -> 2. Build -> 1. Projects" to:

    $/TeamProjectName/HelloWorld1/HelloWorld1/HelloWorld1.csproj
  4. Set "Process -> 2. Build -> 5. Advanced -> MSBuild arguments" to:

    /t:Build;_RemoteBuild /p:HttpPort=%HTTP_PORT%;ServerAddress=%SERVER_ADDRESS%;BSAT=%BSAT%

    Replace %HTTP_PORT%, %SERVER_ADDRESS%, and %BSAT% with the corresponding values from the "Project setup" step 8 from above.

  5. Optionally, set the MSbuild platform to iPhone|Debug, iPhoneSimulator|Debug, or similar.

  6. Save the Build Definition.

Running the build

  1. Right click on the newly created Build Definition, select "Queue New Build", and click "Queue".

  2. With some luck, the build will complete successfully.

At this point, I was also able to build successfully from a "Developer Command Prompt" using MSBuild:

msbuild HelloWorld1/HelloWorld1.csproj /t:Build;_RemoteBuild /p:HttpPort=%HTTP_PORT%;ServerAddress=%SERVER_ADDRESS%;BSAT=%BSAT%

I also quickly tested leaving Visual Studio running with the HelloWorld1 project open, and then queueing and building a different Xamarin.iOS project via the TFS web interface.