How do I set up TeamCity CI so that it unpacks Xamarin components?

mvvmcross, teamcity, xamarin

Solution

I’ve had trouble actually getting the cookie jar to load correctly from the system32 path. I think this is a path virtualization issue that I just don't understand well enough to make heads or tails of.

I ended up adding an environment variable that the tool will read from (I'm its principal author at Xamarin :-) that specifies the cookie jar path to read from, and this solved the problem for others using TeamCity. The environment variable is `COOKIE_JAR_PATH`.

You can set it from TeamCity's environment settings to point to a cookie jar path outside of the system32 profile directory (I think in my original testing, I put it in the root of the C: drive, but it can be anywhere, really).

Problem

In Visual Studio everything works and a Components directory is created with the appropriate dlls. However, TeamCity is not able to retrieve the Android Support Library dlls because the trigger for the restore is a Xamarin VS plugin that runs when loading the solution. The equivalent of nuget package restore for Xamarin is xamarin-component. I have placed the xamarin-component.exe in my C:\Windows directory. To configure TeamCity, I prepended a Command Line build step with ``` Command executable: xamarin-component Command parameters: restore mysolution.sln ``` TeamCity runs as NT Authority\System. So using PsExec, ``` psexec -i -s %SystemRoot%\system32\cmd.exe ``` If I then run 'xamarin-component login' ``` INFO (login): Computed cookie jar path: C:\Windows\system32\config\systemprofile\.xamarin-credentials INFO (login): Computed cookie jar path: C:\Windows\system32\config\systemprofile\.xamarin-credentials INFO (login): Credentials successfully stored. ``` When I go to my solution in cmd and attempt the restore, I get an attempt to download the componet, and then a Json parsing error. This is the same error I get in TeamCity. I get the error if I use 'Administrator' (which stores the credential in C:\Users\Administrator. Earlier when I was using my personal account, it did work. However, once I deleted the C:\Users\tim\AppData\Local\Xamarin\Cache\Components, the same issue emerged. Fiddler shows that rather than getting Json back (as we do when we enter an invalid token) we are getting a 302 redirect that says Object moved here. And here is the xamarin login page - obviously not Json. Tried. 1. Set COOKIE_JAR_PATH to C:\Users\tim.xamarin-credentials - xpkg picks up but same error 2. Copy .xamarin-credentials from Config\system32 to D:\, set COOKIE_JAR_PATH to D:.xamarin-credentials - xpkg picks up but same error 3. Move .xamarin-credentials to C:\, set COOKIE_JAR_PATH - same error 4. Re-login in NT Authority with COOKIE_JAR_PATH to C:.xamarin-credentials - same error My temporary idea now is to figure out where the NT Authority xamarin-component looks for Cache and put the files there. ``` C:\Windows\system32\config\systemprofile\AppData\Local\Xamarin\Cache\Components\xamandroidsupportv4-18-4.18.1.xam ``` The version of my xamarin-component is 0.99 - for 100, we try harder...

Original source