Command line build and nuget packages

I already have a command line build working using mdtool. However, I have switched to getting my dependencies via nuget. When I launch XamStudio, it automatically downloads the nuget packages making the build successful. However, a command line build does NOT automatically download the packages from nuget servers. What command can I run to cause that to happen?


  • mattwardmattward GBMember Xamurai
    edited June 2014

    To download the NuGet packages from the command line you can use NuGet.exe. You can restore the packages using a command similar to the following if you are running on the Mac:

    mono --runtime=v4.0 nuget.exe restore YourSolution.sln

    For Windows you can use:

    nuget.exe restore YourSolution.sln

    You should be able to use the official NuGet.exe from the main NuGet codeplex site.

    If that does not work you can use the NuGet.exe that ships with Xamarin Studio which can also be downloaded separately. You will need all the binary files from GitHub (NuGet.exe, NuGet.Core.dll and Microsoft.Web.XmlTransform.dll )

    Another alternative is to use the MSBuild based package restore which would restore during the build. This has been deprecated by the NuGet team since there are problems with NuGet packages that include custom MSBuild targets. Xamarin Studio does not have a way to enable this feature so there is not an easy way to set this up on the Mac. I would recommend using NuGet.exe restore.

  • Thanks, that did the trick!

  • jeffryvujeffryvu NLMember, University

    On Mac you can just do
    nuget restore YourSolution.sln, right?

    as nuget is already in the path when you install Xamarin. So, without the .exe.

    How is that different from
    mono --runtime=v4.0 nuget.exe restore YourSolution.sln?

  • mattwardmattward GBMember Xamurai

    @JeffryvandeVuurst‌ - Correct you can just run nuget restore YourSolution.sln on the Mac.

    Recent versions of Mono (after 3.6) ship with NuGet so you do not need to use a separate download of NuGet.exe. When I posted that original comment I think mono 3.4 was the latest stable version and NuGet was yet not being included.

  • AdnanKhanAdnanKhan USMember ✭✭
    edited October 2015

    I have a test IOS 9.0 CocoSharp project and when run this command:

    nuget restore YourSolution.sln

    it gives me error any idea? Thank You
    Error reading '/....GameName.IOS/packages.config'
    I am using : nuget.exe - latest (v3.2.0)

  • mattwardmattward GBMember Xamurai
    edited October 2015

    The error does not really indicate anything apart from there being an error reading the packages.config file. Try adding the -verbosity detailed flag to the command line to get the full callstack.

    nuget restore YourSolution.sln -verbosity detailed
  • RuchiDeviRuchiDevi USMember ✭✭
    edited November 2018

    I am trying for CI: integrating xamarinform with jenkin.

    Having installed visual studio for Mac

    Using following command for nuget restore:

    /Library/Frameworks/Mono.framework/Versions/5.16.0/bin/mono --runtime=v4.0 /Library/Frameworks/Mono.framework/Versions/5.16.0/bin/nuget.exe restore XamarinSampleCI.sln

    But it is not not working. Getting following error:

    • /Library/Frameworks/Mono.framework/Versions/5.16.0/bin/mono --runtime=v4.0 /Library/Frameworks/Mono.framework/Versions/5.16.0/bin/nuget.exe restore XamarinSampleCI.sln
      Cannot open assembly '/Library/Frameworks/Mono.framework/Versions/5.16.0/bin/nuget.exe': No such file or directory.
      Build step 'Execute shell' marked build as failure
      Finished: FAILURE

    please help. how can I fix this issue @mattward

  • mattwardmattward GBMember Xamurai

    Looking at Mono 5.18 there is no 'nuget.exe' in a similar location to what you are using. Instead there is a nuget script file at that location which you should be able to use instead.


    I suspect that is the same with Mono 5.16.

    Another idea here would be to use /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget since that is what is referred to if you run which nuget.

    Or you can just use the full path to NuGet.exe:

  • RuchiDeviRuchiDevi USMember ✭✭
    edited November 2018

    I tried using following command:

     /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0    
     /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget restore XamarinSampleCI.sln

    But still getting error with following log:
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0 /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget restore XamarinSampleCI.sln
    Cannot open assembly '/Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget': File does not contain a valid CIL image.
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE

    Tried this command as well:

     /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0     
     /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/nuget/nuget.exe restore XamarinSampleCI.sln

    But Getting following error:

    • /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0 /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/nuget/nuget.exe restore XamarinSampleCI.sln
      MSBuild auto-detection: using msbuild version '15.0' from '/Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin'.
      MsBuild.exe does not exist at '/Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin'.
      Build step 'Execute shell' marked build as failure
      Finished: FAILURE

    @mattward Thanks for quick response.

  • mattwardmattward GBMember Xamurai

    The following command will not work. You do not need to specify the mono path since here you are using the nuget script which already does that for you.

    /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0    
     /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget restore XamarinSampleCI.sln

    The second command line looks OK to me. It seems as though NuGet is misbehaving for some reason. The 'MSBuild.exe does not exist at' message seems to be from this line of code in NuGet. Looking at how msbuild is detected after the path is found it looks like it cannot find msbuild on the path. NuGet seems to ignore the path to msbuild it has already found in most cases and then try to find it on the path.

    On my machine msbuild is on the path by being available in the directory: /Library/Frameworks/Mono.framework/Versions/Current/Commands

    which msbuild for me returns: /Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild.

    So I would guess that this directory is not part of the PATH for the CI build server account.

    The error message you are getting seems to suggest it is reaching this line since it is returning a directory not a file, which seems like a NuGet bug. So I think you would have to ensure that /Library/Frameworks/Mono.framework/Versions/Current/Commands is on the path.

  • RuchiDeviRuchiDevi USMember ✭✭

    I tried using this command with -MSbuildPath /Library/Frameworks/Mono.framework/Versions/Current/Commands:

    /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0  
    /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/nuget/nuget.exe restore XamarinSampleCI.sln
    -MsbuildPath /Library/Frameworks/Mono.framework/Versions/Current/Commands

    But getting following error:

    Library/Frameworks/Mono.framework/Versions/Current/Commands/mono --runtime=v4.0
    /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/nuget/nuget.exe restore XamarinSampleCI.sln -
    MsbuildPath /Library/Frameworks/Mono.framework/Versions/Current/Commands
    Using Msbuild from '/Library/Frameworks/Mono.framework/Versions/Current/Commands'.
    Error parsing solution file at /Users/.jenkins/workspace/TestOne/XamarinSampleCI.sln: Invalid Image
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE


  • mattwardmattward GBMember Xamurai

    Specifying the -msbuildpath will not work since this is mostly ignored by NuGet. You will need to ensure /Library/Frameworks/Mono.framework/Versions/Current/Commands is on the path. Also pointing -msbuildpath to this Commands path is incorrect - this is not the real path to msbuild.

  • RuchiDeviRuchiDevi USMember ✭✭

    "You will need to ensure /Library/Frameworks/Mono.framework/Versions/Current/Commands is on the path."

    I am running nuget restore command at jenkin. can you please guide how to set msbuild path?

    @mattward Thanks.

  • mattwardmattward GBMember Xamurai

    Sorry, I do not work with Jenkins.

    Can you not just export a new path before running the nuget command?

    export PATH="$PATH:/Library/Frameworks/Mono.framework/Versions/Current/Commands"
Sign In or Register to comment.