简体   繁体   中英

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"

I'm trying to run the following NuGet commands:

$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. : The PowerShell version is 5.1 and NuGet is 4.6.**This code works fine through Windows CMD.

On the CMD command line I run it like this, and it works:

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 CLI reference

I think you are missing the config parameter if you are trying to set the proxy:

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

config command (NuGet CLI)

NuGet behind a proxy

To run with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM