'nuget' is not recognized but other nuget

2019-01-16 15:52发布

问题:

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.

回答1:

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.



回答2:

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:

  • Download NuGet.exe from https://github.com/NuGet/NuGet.Client/releases (give preference for the latest release);
  • Place NuGet.exe in C:\Program Files\NuGet\Visual Studio 2012 (or your VS version);
  • Add C:\Program Files\NuGet\Visual Studio 2012 (or your VS version) in PATH environment variable (see http://www.itechtalk.com/thread3595.html as a How-to) (instructions here).
  • Close and open Visual Studio.

Update

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

Install-Package NuGet.CommandLine



回答3:

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.



回答4:

In [Package Manager Console] try the below

Install-Package NuGet.CommandLine


回答5:

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

https://github.com/nuget/home



回答6:

In Visual Studio:

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

In PM:

Install-Package NuGet.CommandLine

Close Visual Studio and open it again.



回答7:

  • Right-click on your project in solution explorer.
  • Select Manage NuGet Packages for Solution.
  • Search NuGet.CommandLine by Microsoft and Install it.
  • On complete installation, you will find a folder named packages in your project. Go to solution explorer and look for it.
  • 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.
  • Inside NuGet.CommandLine.3.5.0 look for a folder named tools.
  • Inside tools you will get your nuget.exe


回答8:

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.