nuget on mono

The common usage of NuGet is a Visual Studio extension that makes it easy to install and update third-party libraries and tools in Visual Studio. But Visual Studio only run natively in windows (other OS need emulator layer or virtualization to make it running).

Nuget is useful in Linux server where MVC sites are deployed or used as build server for deployed Desktop Application and we used nuget package as third party library. Usually we include nuget package in version control or include any dll in bin folder of MVC. Nuget package has lot of unnecessary files to include in version control.

Using nuget in server and retrieve or restore nuget package in application is the preferable solution. But, only command line version of nuget is can be used in server.

First, Download NuGet command line (NuGet.exe) at
it will download NuGet.exe (bootstarp version)

Update: I’m using my own compiled mono which reside in /opt/mono, it may be different to your mono installation. Removed the path.

if we try to execute
# mono NuGet.exe

its will throw errors

Unhandled Exception: System.Net.WebException: Error getting response stream (Trust failure): TrustFailure
---> System.IO.IOException: The authentication or decryption has failed.
---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received form server.

its happen because nuget download nuget from https location and as default mono not trust any https certificate, in order to handle https download issue in mono we need to do:
# mozroots --import --sync

After completes, and we try to execute again. its throw another error:

WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727
Missing method .ctor in assembly /opt/src/nuget-bin/NuGet.exe, type System.Runtime.Versioning.TargetFrameworkAttribute
Can't find custom attr constructor image: /opt/src/nuget-bin/NuGet.exe mtoken: 0x0a000787

Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'NuGet'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'NuGet'.

there error raised because default mono uses v 2.0 runtime but nuget ist using v4.0. its can be resolve by define runtime parameter on mono:
mono --runtime=v4.0.30319 NuGet.exe

When we execute again it will successful and download latest NuGet.exe

Additional step to make nuget as script:

put NuGet.exe in mono bin /opt/mono/bin/NuGet.exe
create nuget shell script in /opt/mono/bin/nuget

vi /opt/mono/bin/nuget

exec /opt/mono/bin/mono --runtime=v4.0.30319 --gc=sgen /opt/src/nuget-bin/NuGet.exe "$@"

chmod +x /opt/mono/bin/nuget

how to uses
nuget install Dapper.Rainbow.MySql -Version 0.1.4

it will download require packages to current directory

This entry was posted in Tools and tagged , , , . Bookmark the permalink.

30 Responses to nuget on mono

  1. Thanks a lot for posting this. I was stuck, and your solution fixed my problem!

  2. Great thanks. Slight typo; the command is mozroots.

  3. doyle says:

    try the newest NuGet on Mono 2.10.9 for mac os x 10.7
    “Missing method System.Security.Cryptography.CryptoConfig::get_AllowOnlyFipsAlgorithms() in assembly /Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/mscorlib.dll, referenced in assembly /Users/doylecnn/Downloads/NuGet.exe
    Method not found: ‘System.Security.Cryptography.CryptoConfig.get_AllowOnlyFipsAlgorithms’.”

    • antonhasan says:

      I have test new nuget version (v2.0.0) and throw same error on mono 2.10.8 but update to latest mono fix the problem, also have tested on mono master 2.11.2 and works as expected. But test using latest git of mono 2.10.9 throw same error, fortunately this problem already fixed in nuget codeplex. So the solution is downgrade to mono 2.10.8 or upgrade to mono master 2.11.2 or we have to wait nuget latest release which contain the fix for the bugs

  4. Max says:

    When I try mono nuget.exe I do not see an exception but instead get:

    macs-mac-mini:Downloads MacMini$ mono –runtime=v4.0 ./NuGet.exe
    ApplicationName=’/Users/MacMini/.local/share/NuGet/NuGet.exe’, CommandLine=”, CurrentDirectory=’/Users/MacMini/Downloads’

    Do you have any idea why I’m not getting a proper exception?

    • Max says:

      Upgraded to mono 2.11.2 and get the above plus “Native error= Cannot find the specified file”

      • nicolas says:

        I have the same pb on my macbook air, but not on my macmini.. dont know what difference there is yet.. have you found anything ? oddly enough, when I launch mono /Users/me/.local/share/NuGet/NuGet.exe, which seems to be a copy created by mono, it works fine..

    • Max says:

      I also do not have the /opt/mono directory

    • antonhasan says:

      I think you running NuGet.exe launcher generate by visual studio nuget package restore. i have encounter this also when testing NuGet v2.0. the complete NuGet.exe binary actually reside in Application Name Value (‘Users/MacMini/.local/share/NuGet/NuGet.exe’). i have try debugging this but seem that this launcer access NuGet.exe which in OSX or Linux non natively handle except by prepend mono program before it. i have try to mimic the launcher with my self created launcer without success. so the only solution currently just execute full binary NuGet.exe instead of that launcer

      • Max says:

        If I run Users/MacMini/.local/share/NuGet/NuGet.exe I get the nuget help! Cheers for that. Why did the original binary put this one here? If I pop the NuGet.exe in my $PATH will I be able to do mono nuget without specifying the path to the executable or do I have to copy nuget to /usr/bin ?

      • antonhasan says:

        You can put the NuGet.exe location to your path, or link to your bin path (/usr/bin) or copy it.. it just matter of taste.. all will work 🙂

      • Max says:

        This really helped me out. Thanks so much!

        Do you know if the packages contain powershell scripts that they will work on mono / mac os ?

      • antonhasan says:

        You’re welcome. unfortunately powershell support in mono is very basic therefore nuget powershell integration will not work in mono.

      • Max says:

        Gah! So close!

        I now get WARNING: Could not connect to the feed specified at ‘’. Please verify that the package source (located in the Package Manager Settings) is valid and ensure your network connectivity.

        I thought I was there 😉

      • Max says:

        Rolling back to mono 2.10.9 has made it work 🙂 What a journey, I wish I was in Windows!

  5. Kay says:

    Great post. I had almost made it through but I got stuck at installing a package.
    # nuget install Dapper.Rainbow.MySql -Version 0.1.4
    error – “Could not load type ‘NuGet.Commands.ProjectFactory’ from assembly ‘NuGet, Version=2.0.30619.9000, Culture=neutral, PublicKeyToken=null’.”

    In the nuget script which you have created, where did you get the path for NuGet.exe as ‘/opt/src/nuget-bin/NuGet.exe’? I was under the impression that the path was, ‘/opt/mono/bin/NuGet.exe’.

  6. firegrass says:

    If someone on windows would build nuget trunk and share nuget.exe it would make things a lot easiler!

    Why nuget team haven’t put out a new release with this fix is stupid. They know it’s trashed on mono and that linux/mono users can’t build the trunk. So effectively they have no release at the moment for mono. Great!

  7. I got this error message on Ubuntu Linux 12.04:

    shantanu@~$ mono –runtime=v4.0.30319 ~/bin/NuGet.exe
    ApplicationName=’/home/shantanu/.local/share/NuGet/NuGet.exe’, CommandLine=”, CurrentDirectory=’/home/shantanu’

  8. Macropus says:

    Thanks for this – helped me install Nuget on OSX Mountain Lion

  9. Pingback: Using Reactive Extensions with Mono « Maurits thinks aloud

  10. Vovan says:

    By the way, has anyone tryed to use mono-nuget (to grab say NancyFx, which I cannot compile from github’s sources) on Cloud9 (

  11. Pingback: Test Driving F#: String Calculator Kata | Simon Says

  12. Pingback: Blinking an LED with Raspberry Pi 2 and Mono « RJ Dudley

  13. Pingback: Install command line nuget on Ubuntu server - TUTB

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s