[英]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.