Running NuGet command-line on Linux

Feb 24, 2013 - 2 min read

NuGet probably won’t work out of the box if you are running on Linux. However, it’s possible with a few twists and turns. At the time this article was written, current NuGet command-line version was 2.2. Linux Mint 14.1 Mate x64 was used for testing.

Note: There is a small quirk when using NuGet on Linux: it ignores output directory setting in your custom nuget.config, but you can use the -o [directory] argument to specify the output directory.

Steps

  1. Install mono-complete using software manager for your OS
  2. Import Mozilla LXR certificates into Mono with mozroots --import --sync
  3. Download the NuGet.exe Command Line (not the bootstrapper) from the NuGet releases page
  4. Download Microsoft.Build.dll and copy it to the same directory as NuGet.exe. (also found in Mono installation for Windows, under Program Files (x86)\Mono-_version_\lib\mono\4.0.)
  5. Run NuGet with specific runtime using mono --runtime=v4.0 NuGet.exe

Troubleshooting

Mscorlib.dll Error

Running mono NuGet.exe for the first time might output this error:

The assembly mscorlib.dll was not found or could not be loaded.
It should have been installed in the `/usr/lib/mono/2.0/mscorlib.dll' directory.

Solution: Install mono-complete using software manager for your OS.

WebException Error

If running mono NuGet.exe outputs an error like the one below, certificates need to be imported into the Mono certificate store:

NuGet bootstrapper 1.0.0.0
Found NuGet.exe version 2.2.1.
Downloading...

Unhandled Exception: System.Net.WebException:
Error getting response stream (Write: The authentication or decryption has failed.): SendFailure --->
System.IO.IOException: The authentication or decryption has failed. --->
Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
  at Mono.Security...(snip)

Solution: Import Mozilla certificates first with mozroots --import --sync.

Unavailable Runtime Version Error

If running mono NuGet.exe outputs an error like the one below, you need to run it with a different runtime:

WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727

Unhandled Exception: System.TypeLoadException:
Could not load type 'NuGet.Program' from assembly 'NuGet, Version=2.2.40207.9053, Culture=neutral, PublicKeyToken=null'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException:
Could not load type 'NuGet.Program' from assembly 'NuGet, Version=2.2.40207.9053, Culture=neutral, PublicKeyToken=null'.

Solution: Run with a different runtime using mono --runtime=v4.0 NuGet.exe.

NuGet.Commands.ProjectFactory Error

If you see an error like the one below, you need to have Microsoft.Build.dll next to your NuGet.exe. This will probably be fixed in Mono 3.

Could not load type 'NuGet.Commands.ProjectFactory' from assembly
'NuGet, Version=2.2.40207.9053, Culture=neutral, PublicKeyToken=null'.

Solution: Download Microsoft.Build.dll and copy it next to NuGet.exe.