首页 > 解决方案 > Windows Server 2012:Powershell 无法识别 NuGet

问题描述

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

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在存在的目录中执行,它工作正常nuget.exe

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

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

标签: c#.netpowershellnugetwindows-server-2012

解决方案


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

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

文档中所述,

作为一项安全功能,PowerShell 不运行可执行(本机)命令,包括 PowerShell 脚本,除非该命令位于 Path 环境变量 $env:path 中列出的路径中,或者除非您指定脚本文件的路径。


推荐阅读