powershell不能调用nuget.exe命令

发布于 2025-02-10 23:51:55 字数 1277 浏览 1 评论 0原文

我有一个powershell脚本,可以检查nuget.exe是否存在,并且运行'nuget help',

# Check if NuGet.exe is available.
if (-not (Get-Command "NuGet.exe" -ErrorAction SilentlyContinue)) 
{ 
    Write-Host "ERROR: NuGet.exe is not available. Install NuGet.exe and add to PATH or copy NuGet.exe into C:\Windows."
    exit
}
Write-Host "Confirmed NuGet.exe is in the path."

# run nuget command
$result = Invoke-Executable NuGet.exe "help"

Write-Host "result = $result"

如果我运行脚本,我在运行nuget.exe命令时会出现错误,即使找到了nuget.exe:

Confirmed NuGet.exe is in the path.
Invoke-Executable : The term 'Invoke-Executable' 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 D:\repos\xdcr-nuget\packaging and publishing\auto.ps1:9 char:11
+ $result = Invoke-Executable NuGet.exe "help"
+           ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-Executable:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
result =

在我的外面 :脚本,仅从powershell命令行我可以运行nuget命令,例如nuget help完全可以。但是,如果没有此错误,PowerShell脚本无法运行任何Nuget命令,我在设置PowerShell脚本的方式上做错了什么?

I have a powershell script which checks if nuget.exe exists, and runs 'nuget help'

# Check if NuGet.exe is available.
if (-not (Get-Command "NuGet.exe" -ErrorAction SilentlyContinue)) 
{ 
    Write-Host "ERROR: NuGet.exe is not available. Install NuGet.exe and add to PATH or copy NuGet.exe into C:\Windows."
    exit
}
Write-Host "Confirmed NuGet.exe is in the path."

# run nuget command
$result = Invoke-Executable NuGet.exe "help"

Write-Host "result = $result"

if I run the script, I get an error when running the nuget.exe command, even though it says nuget.exe was found:

Confirmed NuGet.exe is in the path.
Invoke-Executable : The term 'Invoke-Executable' 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 D:\repos\xdcr-nuget\packaging and publishing\auto.ps1:9 char:11
+ $result = Invoke-Executable NuGet.exe "help"
+           ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-Executable:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
result =

outside of my script, just from the powershell command line I can run nuget commands such as nuget help perfectly fine. but the powershell script is unable to run any nuget command without this error, am i doing something wrong with how I setup my powershell script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文