Wednesday, July 6, 2016

Xamarin Build Services - Nuget Restore with VSTS

Recently I wrote a post about about setting up a continuous delivery process using VSTS, Xamarin and MacInCloud. One of the things I mentioned was using the restore Nuget packages task in order to make sure the appropriate files were available to the build server. It seemed to work great in my test project. Then I was working with a real project using the same process and introduced MvvMCross into the mix; suddenly I encountered an error on the build server similar to "'MvvmCross.Core' already has a dependency defined for 'MvvmCross.Platform'." Here is a Stackoverflow discussion on this:

http://stackoverflow.com/questions/37838587/mvvmcross-wont-restore-when-running-nuget-restore-error-mvvmcross-core-alrea

The Problem:
This error is caused by the version of Nuget that is currently deployed with the Xamarin Studio on the Mac has problems with certain Nuget restore operations. After conferring with the support group from MacInCloud they stated a solution similar to what I am detailing here might work, it did.

The Solution:
Do not use the Nuget restore task in VSTS, instead deploy the latest version of Nuget in your source control and include a shell script to restore the packages using a newer version of Nuget.

Steps:
1) Download the latest version of Nuget.exe and add it to your source control repository. You can download it from the following site. You should get the latest 3.X version.

https://docs.nuget.org/consume/installing-nuget

Take the downloaded nuget.exe and place it in a directory in your repository. I placed mine under a folder called Nuget off the repository root.

2) Create a shell script file. It is just a text file with a .sh extension. I called mine nugetrestore.sh. In the file is a single line:

mono nuget/nuget.exe restore $1

I saved this file to the root of the repository.

3) Add a new shell script task to the build script in VSTS. The Script Path points to the location of the nugetrestore.sh file in the repository and the Arguments setting should point to the solution file that Nuget packages need to be restored for.



With this alternative method of restoring Nuget packages on a Mac build server, more complex restores work without the errors that are encountered using the default Nuget restore task.



3 comments:

  1. Great to read your article but I think you need more Exposer to your talent So Xamarin Services

    ReplyDelete
  2. This is probably the best, most concise step-by post on Nuget Restore with VSTS. All your hard about curating this informative post on Xamarin Developer tips is much appreciated.

    ReplyDelete
  3. Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. Hire xamarin developer india, xamarin development company

    ReplyDelete