Windows Server 2012:Powershell 无法识别 NuGet

Windows Server 2012: Powershell is not recognizing NuGet

我遇到 nuget.exe 在 Windows Server 2012 中无法被 Powershell 识别的情况。我很确定环境变量已正确设置。但是我收到以下错误:

nuget : 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 again.
At line:1 char:1
+ nuget
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (nuget:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

即使我转到存在 nuget.exe 的目录并执行 nuget.

,我也会遇到同样的错误

Windows CMD 显示 nuget is not a recognized command,但如果我在存在 nuget.exe 的目录中执行 nuget,它工作正常。

我在为 nuget 设置环境变量时犯了错误吗?请帮助:)

注意:我是 dotnet 技术生态系统的新手。

与许多 Unix 系统一样,Powershell 不在路径中包含当前目录。需要使用完整路径或明确包含当前目录。

在 Nuget 的目录中尝试 .\nuget.exe

documentation

中所述

As a security feature, PowerShell does not run executable (native) commands, including PowerShell scripts, unless the command is located in a path that is listed in the Path environment variable $env:path or unless you specify the path to the script file.

您的路径变量应该是包含您的目录的以分号分隔的路径列表:在我的一个 Server 2012 盒子上,它看起来像这样:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server0\DTS\Binn\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Windows Kits\Windows Performance Toolkit\;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\TShell\TShell\;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\Program Files (x86)\dotnet\

有点长而且笨拙。您应该将您的 NuGet 路径附加到此字符串并保存。

Windows Explorer,右键单击 This PC => Properties。在左侧面板上找到 Advanced system settings。选择 Advanced 选项卡。单击右下角的 Environment Variables 按钮。向下滚动 window,直到找到 Path 变量。

我一般都是复制粘贴to/from一个文本编辑器,方便使用。