1

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= txxxxxx"
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=txxxxxx
nuget.exe config -set http_proxy.password= njhbjhb
6
  • But even when I coment the third command It does not work. I will remove it from there, so it is more clear. Commented Aug 15, 2018 at 11:48
  • If you have working batch code, post that in your question. Commented Aug 15, 2018 at 11:52
  • Sorry I am not running it through batch file, but I added there how I am running it directly through CMD Commented Aug 15, 2018 at 12:07
  • I get "Unknown command: '-set'" running nuget.exe -set http_proxy.user= t123654 with cmd.exe and NuGet 4.7.1.5393 (latest stable) and NuGet 4.6.2.5055. Commented Aug 15, 2018 at 12:52
  • How strange, for me it runs smothly through cmd. I just run it now to assure and everything is ok, my Nuget.config is updated. Are you running from the nuget.exe directory? Commented Aug 15, 2018 at 13:14

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Actually I alredy have this working, but with cmd command line. What I need now is to run this code in a powershell script.
and you should be able to do it with Invoke-Expression if you prefer: stackoverflow.com/a/3593445/1426007
0

I solved it. It is just about the way of writing it. It should be like this:

.\nuget config -Set http_proxy.user=txxxxxx

.\nuget config -Set http_proxy.password=njhbjhb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.