Bug 36181 - Xamarin TFS build fails after update to Xamarin 4
Summary: Xamarin TFS build fails after update to Xamarin 4
Status: RESOLVED DUPLICATE of bug 35894
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: XMA ()
Version: 4.0.0 (C6)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Adrian Alonso
URL:
Depends on:
Blocks:
 
Reported: 2015-11-23 18:28 UTC by Jon Goldberger [MSFT]
Modified: 2015-12-10 22:23 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 35894

Description Jon Goldberger [MSFT] 2015-11-23 18:28:53 UTC
## Description (from customer):

"Since upgrading to Xamarin 4.0 and using the new Xamarin Mac Agent we are unable to build from TFS.

Our original TFS build definition handled the IPA build with the previous version of Xamarin, however the new version does not force the connection of the Xamarin Build Agent

/p:GenerateProjectSpecificOutputFolder=true /tv:14.0 /p:VisualStudioVersion=14.0 /p:GenerateBuildInfoConfigFile=true /p:Platform=iPhone

We therefore get the following error.

The project TeacherAppClientSharedUIiOS was built while disconnected from a Mac agent, so only the main assembly was compiled. Connect to a Xamarin Mac build agent to build the full application.

Specifying the Mac build server

/p:GenerateProjectSpecificOutputFolder=true /tv:14.0 /p:VisualStudioVersion=14.0 /p:GenerateBuildInfoConfigFile=true /p:ServerAddress=10.128.103.80 /p:ServerUser=Admin /p:ServerPassword=XXXXXXXXXXXXX /p:Platform=iPhone

we receive the following error (with our without a password specified)

C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets (507): Building from the command-line requires a Business license.

We have business licenses for Xamarin and by building from the Building machine the relevant password chain should have been generated.

Building directly from the build machine from visual studio (ensuring that the Xamarin build agent is connected, the build agent appears to loose connectivity when Visual Studio is restarted) builds the IPA as expected.

Is there any additional advice for determining if the Xamarin build agent connection is valid of a facility to force the use of a specific Xamarin license from the build server?

We have left the Mac unlocked as recommend and the Firewall settings are setup as recommended."


## Notes

I verified with the customer that they have gone over the new guide for using TFS with XMA [1] and the XMA trouble shooting document [2]. Also had them make sure the Mac build host was logged in to a valid Xamarin Business or higher account. 

Additional logs and other info from the customer in private comments below.

[1] https://developer.xamarin.com/guides/cross-platform/ci/configuring_tfs/connect-tfs-xamarin/
[2] https://developer.xamarin.com/guides/ios/getting_started/installation/windows/xamarin-mac-agent/xma-troubleshooting/
Comment 9 Jon Goldberger [MSFT] 2015-12-01 20:29:49 UTC
Customer is still not able to build iOS apps from TFS. 

>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning VSXRunBuildLocally: The project TeacherAppClientMarksheetUIiOS was built while disconnected from a Mac agent, so only the main assembly was compiled. Connect to a Xamarin Mac build agent to build the full application. [D:\Builds\20\Mobile\Client\src\Code\TeacherApp.Client.Marksheet.UI.iOS\TeacherApp.Client.Marksheet.UI.iOS.csproj]


It seems they are unable to connect from TFS, though it works from Visual Studio.
Comment 11 Jon Goldberger [MSFT] 2015-12-03 18:10:04 UTC
Possibly related bug #35894
Comment 12 Jon Goldberger [MSFT] 2015-12-04 21:26:26 UTC

*** This bug has been marked as a duplicate of bug 35894 ***
Comment 13 Ace Olszowka 2015-12-10 22:03:26 UTC
We're duping it over here too when we're invoking from CruiseControl.NET and our MSBuild script didn't occur until the latest roll.

The problem appears to be that they've made several changes to the _SayHello target (located in Xamarin.iOS.Windows.After.targets, in the normal install location of C:\Program Files (x86)\MSBuild\Xamarin\iOS).

When this update occurred the developer neglected to properly initialize the following variables from within the msbuild script:

$(ServerPort)
$(ServerAddress)
$(ServerUser)
$(ServerPassword)
$(ServerKeychainPassword)
$(GenerateCache)
$(ContinueOnDisconnected)
$(BuildingInsideVisualStudio)

These variables are set when this process is run via Visual Studio. The developer probably did not test running outside of the Visual Studio environment, and thus did not catch the issue.

The question becomes which of these are critical to the operation of this task? Looking at the Task none of these properties are defaulted, thus we'll assume that we need all of them.

First let’s start with features that have been added, the $(ContinueOnDisconnected) appears to be a new and useful property, if the SayHello Task (which is responsible for communicating with the Mac Build Server) fails for any reason this is the value returned, thus setting this to false will ensure that our builds don't attempt to continue on if we can't get to the build server. This is a great addition, and everyone invoking their projects via MSBuild should set this to false so you fail fast.

Next let’s take a look at the $(ServerAddress), this is pretty straight forward, this as you would expect should be set to the address of the mac build server. 

Now we should look at $(ServerPort), unfortunately we don’t get too many clues on what this should be, however it looks like this is defaulted to port 22 (SSH) which would make sense as the “new” remote build host seems to be implemented over SSH. Additionally, the seemly unrelated $(BuildingInsideVisualStudio) also plays into this, you are not allowed to repoint the Port if it is set to false.

Next we should look at the $(ServerUser) property, we can gather based on the fact that this is using SSH it probably should be the user we’ve setup to be our build host as per their documentation, low and behold that seems to work.

Next is $(ServerPassword) and $(ServerKeychainPassword) I’d hate to send these in the clear, so I tried testing without them, much to my surprise it seemed to work! The question is how is this possible? As far as I can tell this should have fallen right over, I’d find it hard to believe that it’d allow me to connect without any type of password, the only thing I can think of is perhaps they are using some ssh key-based login that is squirrelled off somewhere (probably setup when you first use the Visual Studio GUI to perform the pairing to the mac build host). $(GenerateCache) also did not seem to have any affect.

On the plus side it looks like a long standing bug (the one where the IPA was not copied back when building via MSBuild) has been fixed! Rejoice my fellow Build Masters, you can rid yourselves of the pscp hacks to pull back from the ~/Library/Caches/Xamarin/mtbs/builds/AppiOS/<BuildSessionID>/bin/iPhone/Ad-Hoc/<IPAName>

It is interesting to note that you must still be logged into the Mac Build server, failure to do so yields these warnings (and fails if you’ve got ContinueOnDisconnected set to false):
(_SayHello target) -> 
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : Failed to execute 'ls /usr/bin/mono': ExitStatus=1 [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : ls: /usr/bin/mono: No such file or directory [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : Failed to execute 'ls /usr/bin/mono': ExitStatus=1 [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : ls: /usr/bin/mono: No such file or directory [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : Failed to execute 'launchctl load -S Aqua /tmp/com.xamarin.build.940960d8/app.plist': ExitStatus=112 [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : Could not find domain for  [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : The user 'YourUsername' must be logged in on the mac in order to start the agent. Please make sure the user 'YourUsername' is logged in and try to connect to the mac again. [C:\Build\App.iOS.csproj]C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning :  [C:\Build\App.iOS.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): warning : The user 'YourUsername' must be logged in on the mac in order to start the agent. Please make sure the user 'YourUsername' is logged in and try to connect to the mac again. [C:\Build\App.iOS.csproj]

tl;dr; Ensure that your remote user is logged on to the mac build server and set the following msbuild properties to their correct settings: 
$(ContinueOnDisconnected) = false
$(BuildingInsideVisualStudio) = false
$(ServerAddress) = Mac Build Server
$(ServerUser) = Username of user on mac build server
Nothing else seems to matter. Long standing bug involving IPA not getting copied back also fixed.
Comment 14 Guillaume 2015-12-10 22:10:11 UTC
@Ace Olszowka cool for the IPA copied back fixed. Did you check for the .dSym too?
Comment 15 Ace Olszowka 2015-12-10 22:14:42 UTC
@Guillaume No dice on that, it doesn't appear to be in the /bin/iPhone/Ad-Hoc/ folder though either on the Remote Build Server, but I've never been told to grab that file; so unsure if its been missing since day 1. Is there a particular setting that must be set to generate those?
Comment 16 Guillaume 2015-12-10 22:23:47 UTC
@Ace Olszowka, no there is no settings to get it, it is generated by default. You need it in order to symbolicate crash reports generated from the built IPA/APP. If you don't save it, you will not be able to get a comprehensible stack trace but only a stack of pointer address!
You can find more details here http://jmillerdev.net/symbolicating-ios-crash-files-xamarin-ios/