"nuget"未被识别,但其他nuget命令可以正常工作

166

我正在尝试创建一个NuGet包,参考http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory。 我的Visual Studio中的包管理器控制台不允许我使用“nuget”命令。 我能够使用“Get-help nuguet”并显示以下NuGet cmdlets。

    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.
  • 然而,每当我以nuget开头的命令时会出现以下错误:

'nuget'不是识别的cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,如果包含路径,请验证路径是否正确并重试。

在第1行第6个字符处: + nuget <<<< + CategoryInfo : ObjectNotFound: (nuget:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

我尝试了以下解决方案:

1. 关闭所有项目并重新启动。

2. 卸载并重新安装。

3. 创建一个PowerShell配置文件(这以前不存在,实际上这破坏了一切)。

这个问题在我将Visual Studio 2012 Ultimate试用版升级到注册版之后开始出现。我最初安装了VS 12 Pro。我不知道这是否真的与它有任何关系,但我注意到其他遇到类似问题的人安装了vs 10和12。

我的问题是,“还有谁知道还有什么其他方法可尝试?”我的理论是nuget命令的路径丢失了,但我找不到如何配置软件包管理器控制台使用的路径,也不确定nuget cmdlet实际上存储在哪里。

更新--尝试按照下面的建议下载命令行工具。这导致一切都不起作用了。我试图卸载,现在我在vs2010扩展中有一个关于nuget的项目,但未启用安装或卸载按钮。这让我相信,它与通过2010和2012安装的扩展有关。如果还有人知道如何删除无法卸载的扩展,请告诉我,但我会为此提出另一个问题。


1
你的UAC是否已启用?你尝试以管理员身份运行Visual Studio来卸载扩展了吗? - Betty
1
安装NuGet.CommandLine包是正确的答案。 - live-love
@live-love,OP 正在尝试创建一个包而不是安装一个包。 - Nick Turner
这可能会有所帮助 - stackoverflow链接 - Varun
13个回答

3

您可以在个人资料文件夹中找到 nuget.exe:

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

如果您想要全局使用它,请将上述路径注册到 PATH 环境变量中。

有关如何执行此操作的详细指南,请参阅 在 Windows 10 中添加到 PATH


2
  1. https://www.nuget.org/downloads下载nuget.exe。

  2. 在C盘根目录下创建一个新文件夹,例如c:\nuget,将nuget.exe复制到C盘的nuget文件夹中并粘贴。

  3. 进入环境设置。

  4. 进入系统变量部分 => 选择变量名为Path,双击path变量 => 点击最后的new按钮,在最后添加c:\nuget => 然后应用 => 保存 => 保存。


1

https://www.nuget.org/downloads下载nuget.exe文件。

将下载的文件复制并粘贴到与您的.nupkg文件创建位置相关的文件夹中。

尝试执行命令。


尝试了几个答案后,这一个对我起作用了。 - Mario Perez

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接