163

I am trying to create a nuget package using http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory as a reference. My Package Manger Console in Visual Studio is not allowing me to use the 'nuget' command. I am able to 'Get-help nuguet' and it displays:

The following NuGet cmdlets are included.

    Cmdlet                  Description
    ------------------      ----------------------------------------------
    Get-Package             Gets the set of packages available from the package source.

    Install-Package         Installs a package and its dependencies into the project.

    Uninstall-Package       Uninstalls a package. If other packages depend on this package, 
                            the command will fail unless the –Force option is specified.

    Update-Package          Updates a package and its dependencies to a newer version.

    Add-BindingRedirect     Examines all assemblies within the output path for a project
                            and adds binding redirects to the application (or web) 
                            configuration file where necessary.

    Get-Project             Returns a reference to the DTE (Development Tools Environment) 
                            for the specified project. If none is specifed, returns the 
                            default project selected in the Package Manager Console.

    Open-PackagePage        Open the browser pointing to ProjectUrl, LicenseUrl or 
                            ReportAbuseUrl of the specified package.

    Register-TabExpansion   Registers a tab expansion for the parameters of a command.
  • However, whenever I start off commands with nuget is gives :

The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try ag ain.

At line:1 char:6 + nuget <<<< + CategoryInfo : ObjectNotFound: (nuget:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

I have tried the following solutions:

1>closing down all items and restarting

2> uninstalling and reinstalling

3>creating a powershell profile file (this didn't exist before and this actually broke everything)

The problem started to appear after I upgraded my Visual Studio 2012 Ultimate trial version to registered. I had originally had the VS 12 Pro installed. I don't know if that really has anything to do with it but I noticed that others that had similar problems have vs 10 and 12 installed.

My question is "does anyone know what else to try?" My theory is that the path to the nuget command is missing but I cannot find how to configure the paths the package manager console uses and I am not sure where the cmdlet nuget is actually stored.

Updated---tried downloading the command line tool as suggested below. This lead to nothing working again. I tried to uninstall and now I have a item in vs2010 extentions for nuget that doesn't have a install or unistall button enabled. This leads me to believe that it has to do with extensions installed via 2010 and 2012 that has a part in my little drama. If anyone also knows how to nuke an uninstallable extension, please advise also but I will try another question for that.

done_merson
  • 2,800
  • 2
  • 22
  • 30

13 Answers13

181

Nuget.exe is placed at .nuget folder of your project. It can't be executed directly in Package Manager Console, but is executed by Powershell commands because these commands build custom path for themselves.

My steps to solve are:


Update

NuGet can be easily installed in your project using the following command:

Install-Package NuGet.CommandLine

Leonel Sanches da Silva
  • 6,972
  • 9
  • 46
  • 66
  • What should be entered as 'Variable name'? – Ievgen May 28 '14 at 14:16
  • 1
    I had to place nuget.exe on the same drive as where I was running the nuget command (and adjust the PATH environment variable value accordingly) – mediafreakch Nov 06 '14 at 13:46
  • You can see the PATH environment variable by going to Control Panel > System > Advanced System Settings then on the System Properties window, click Advanced tab and there you will see the "Environment Variables..." button. Under System variables group go find PATH environment variable. Then add another path by delimiting it with a semi-colon (;). – Jerameel Resco Sep 03 '15 at 03:20
  • 1
    There must be some bug.... I get `Package 'NuGet.CommandLine.3.3.0' already exists in project 'TimeLoop'` but when I write NuGet I just get a error that the command doesn't exist. – Peter Dec 01 '15 at 09:30
  • @Peter You can uninstall this version (apparently it was published yesterday) and [use this version instead](https://www.nuget.org/packages/NuGet.CommandLine/2.8.6). – Leonel Sanches da Silva Dec 01 '15 at 13:36
  • @CiganoMorrisonMendez is there a bug in 3.3 ? or does it just require VS 2015 update 1? – Peter Dec 01 '15 at 13:59
  • @Peter Apparently, yes. It didn't work for me in VS2015 without the Update 1. – Leonel Sanches da Silva Dec 01 '15 at 14:11
  • 31
    `Install-Package NuGet.CommandLine` is terrible because, 1. It adds `NuGet.CommandLine` as a dependency to my project (ew!), and 2. It needs to be done separately in every project. `npm` has a 'global install' option - does NuGet not have something similar!? – BlueRaja - Danny Pflughoeft Jan 23 '16 at 08:13
  • @BlueRaja-DannyPflughoeft Until today, no, but this will probably change in NuGet 3.0 stable release. And then I'll have to update my answer. – Leonel Sanches da Silva Jan 23 '16 at 23:32
  • Did this change in Nuget 3.0? – BlueRaja - Danny Pflughoeft May 05 '21 at 23:53
  • @BlueRaja-DannyPflughoeft Have no idea. I'm not actively developing in .NET stack anymore. – Leonel Sanches da Silva May 06 '21 at 15:17
94

In [Package Manager Console] try the below

Install-Package NuGet.CommandLine
Timmeh
  • 398
  • 2
  • 14
BinSys
  • 981
  • 7
  • 3
  • After "Install-Package NuGet.CommandLine",nuget.exe can be execute in PM. – BinSys Dec 16 '14 at 07:18
  • 13
    Execute : The term 'Execute' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. VS2015 – rob Aug 17 '16 at 15:03
  • 3
    Don't type the whole "Execute ..." line. Just type: `Install-Package NuGet.CommandLine` – Serj Sagan Nov 20 '17 at 07:20
  • `Install-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations. At line:1 char:1 + Install-Package NuGet.CommandLine + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand PM> ` – boatcoder May 05 '21 at 16:30
  • 1
    Installs and then still doesn't work. – Ap0st0l Apr 19 '23 at 09:44
67

There are much nicer ways to do it.

  1. Install Nuget.Build package in you project that you want to pack. May need to close and re-open solution after install.
  2. Install nuget via chocolatey - much nicer. Install chocolatey: https://chocolatey.org/, then run

    cinst Nuget.CommandLine

in your command prompt. This will install nuget and setup environment paths, so nuget is always available.

fenix2222
  • 4,602
  • 4
  • 33
  • 56
33

You can also try setting the system variable path to the location of your nuget exe and restarting VS.

  1. Open your system PATH variable and add the location of your nuget.exe (for me this is: C:\Program Files (x86)\NuGet\Visual Studio 2013)
  2. Restart Visual Studio

I would have posted this as a comment to your answer @done_merson but I didn't have the required reputation to do that.

Community
  • 1
  • 1
Matt
  • 1,013
  • 8
  • 16
22

In Visual Studio:

Tools -> Nuget Package Manager -> Package Manager Console.

In PM:

Install-Package NuGet.CommandLine

Close Visual Studio and open it again.

YakovL
  • 7,557
  • 12
  • 62
  • 102
KiranC
  • 597
  • 6
  • 6
  • Install-Package : Failed to add reference. The package 'NuGet.CommandLine' tried to add a framework reference to 'Microsoft.Build.Utilities.v4.0' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance. Reference unavailable. – Markus Aug 11 '22 at 09:31
20

The nuget commandline tool does not come with the vsix file, it's a separate download

https://github.com/nuget/home

hardkoded
  • 18,915
  • 3
  • 52
  • 64
Betty
  • 9,109
  • 2
  • 34
  • 48
13
  • Right-click on your project in solution explorer.
  • Select Manage NuGet Packages for Solution.
  • Search NuGet.CommandLine by Microsoft and Install it. Search Nuget.CommandLine
  • On complete installation, you will find a folder named packages in your project. Go to solution explorer and look for it. packages
  • Inside packages look for a folder named NuGet.CommandLine.3.5.0, here 3.5.0 is just version name your folder name will change accordingly. nuGet COmmand Line
  • Inside NuGet.CommandLine.3.5.0 look for a folder named tools. tools
  • Inside tools you will get your nuget.exe nuget.exe
DeltaCap019
  • 6,532
  • 3
  • 48
  • 70
11

Retrieve nuget.exe from https://www.nuget.org/downloads. Copy it to a local folder and add that folder to the PATH environment variable.

This is will make nuget available globally, from any project.

misha
  • 2,760
  • 3
  • 28
  • 30
  • It's just that easy. Create "c:\Nuget", then go to environment variables, double Path, Click New, put "C:\Nuget" and you're done. Doing everything is visual studio is 2010. Use the Powershell or the command line. – Nick Turner Jun 01 '20 at 20:11
  • Visual Studio should be restarted after changing the PATH, otherwise it's not recognized. – OfirD Aug 08 '23 at 11:28
9

I got around this by finding the nuget.exe and moving to an easy to type path (c:\nuget\nuget) and then calling the nuget with this path. This seems to solve the problem. c:\nuget\nuget at the package manager console works as expected. I tried to find the path that the console was using and changing the environment path but was never able to get it to work in that way.

done_merson
  • 2,800
  • 2
  • 22
  • 30
  • 2
    This should be the accepted answer. It's really not more complicated than this! – Florian Winter Aug 30 '18 at 13:51
  • 1
    Update Nov 2019 - nuget.exe is the .exe needed for Nuget command line tools (via either a Powershell or cmd console, or the Nuget Package Manager Console in VS) - see here https://learn.microsoft.com/en-us/nuget/reference/nuget-exe-cli-reference. If you don't have it get it here - https://www.nuget.org/downloads – Chris Halcrow Nov 29 '19 at 00:07
6

Follow these steps.

  1. In visual studio go to Tools-> NuGet Package Manager->Package Manager Console

  2. Run below command

    Install-Package NuGet.CommandLine

  3. Close visual studio and reOpen again

  4. repeat step 1

  5. run your nuget command eg. nuget push C:\Users\syaads\Debug\Library.1.0.32.nupkg -Source Artifactory

Shakeer Hussain
  • 2,230
  • 7
  • 29
  • 52
3

You can find the nuget.exe in your profile folder:

C:\Users\YourProfileName\.nuget\packages\nuget.commandline\6.0.0\tools

If you want to use it gloablly, please register above path in PATH environment variable.

For detailed guide how to do it, please see Add to the PATH in Windows 10

1_bug
  • 5,505
  • 4
  • 50
  • 58
2
  1. Download nuget.exe from https://www.nuget.org/downloads.

  2. create a new folder in root of C drive e.g c:\nuget, copy the nuget.ext to nuget folder in c drive and paste.

  3. Go to environmental settings.

  4. Go to System Variable Section => select the variable name as Path and double click on path variable => and click on new button in the last add c:\nuget => then apply => save => save.

1

Download the nuget.exe from the https://www.nuget.org/downloads.

Copy and paste the downloaded file to the relevant folder where your .nupkg is created.

Try to execute the command.

Sachith Wickramaarachchi
  • 5,546
  • 6
  • 39
  • 68