简体   繁体   English

如何在PowerShell脚本中运行NuGet命令?

[英]How can I run NuGet commands in a PowerShell script?

I am trying to run some NuGet commands through a PowerShell script, but PowerShell prompts errors like: "Unknown command:'-set'" or "Unexpected token '-set' in expression or statement" 我正在尝试通过PowerShell脚本运行一些NuGet命令,但是PowerShell会提示诸如以下错误:“未知的命令:'-set'”或“表达式或语句中的意外的标记'-set'”

I'm trying to run the following NuGet commands: 我正在尝试运行以下NuGet命令:

$nugetExe = "C:\TestAutomation\NuGet\nuget.exe"

Invoke-Expression "$nugetExe config -set http_proxy.user= t123654"
Invoke-Expression "$nugetExe config -set http_proxy.password= njhbjhb"

PS. PS。 : The PowerShell version is 5.1 and NuGet is 4.6.**This code works fine through Windows CMD. :PowerShell版本为5.1,NuGet为4.6。**此代码可通过Windows CMD正常运行。

On the CMD command line I run it like this, and it works: 在CMD命令行上,我像这样运行它,并且它的工作原理是:

nuget.exe config -set http_proxy.user=t123645
nuget.exe config -set http_proxy.password= njhbjhb

nuget.exe doesn't have a set parameter. nuget.exe没有set参数。

NuGet CLI reference NuGet CLI参考

I think you are missing the config parameter if you are trying to set the proxy: 我认为如果您尝试设置代理,则缺少config参数:

nuget.exe config -set http_proxy=http://my.proxy.address:port

config command (NuGet CLI) config命令(NuGet CLI)

NuGet behind a proxy NuGet支持代理

To run with PowerShell: 要使用PowerShell运行:

$nugetExe = "D:\Scrap\New folder\NuGet.exe"

$Params = @(

    "config",
    "-Set", "HTTP_PROXY.USER=domain\user"
    "-configfile" "D:\scrap\New folder\my.config"
)

& $nugetExe $Params

I solved it. 我解决了 It is just about the way of writing it. 它只是关于编写它的方式。 It should be like this: 应该是这样的:

.\nuget config -Set http_proxy.user=t514144

.\nuget config -Set http_proxy.password=njhbjhb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Powershell 脚本中运行命令? - How do I run commands in a Powershell script? 如何从PowerShell脚本引用NuGet软件包文件? - How can I reference NuGet package files from a PowerShell script? 如何在PHP中运行Powershell脚本? - How can I run a Powershell script in PHP? 如何在 for 循环中运行 powershell 脚本? - How can I run a powershell script in a for loop? 如何以管理员身份使用 powershell 运行 CMD 命令? - How I can run CMD commands as administrator with powershell? 如何在userdata中重新启动多个PowerShell命令? - How can I run multiple PowerShell commands with restarts in userdata? 如何在正常的PowerShell会话中(不在Visual Studio中)运行Nuget PowerShell cmdlet Install-Package? - How can I run Nuget PowerShell cmdlet Install-Package in normal PowerShell session (not inside Visual Studio)? 使用PowerShell脚本运行应用程序(带有命令) - PowerShell script to run application (with commands) 在 PowerShell 脚本中,如何还原包以解决错误:此项目引用此计算机上缺少的 NuGet 包 - In PowerShell script, how can I restore packages to resolve error: This project references NuGet package(s) that are missing on this computer 在安装NuGet之后运行PowerShell脚本 - Run PowerShell script after NuGet install
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM