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
Chewie
  • 31
  • 9
  • But even when I coment the third command It does not work. I will remove it from there, so it is more clear. – Chewie Aug 15 '18 at 11:48
  • If you have working batch code, post that in your question. – Bacon Bits Aug 15 '18 at 11:52
  • Sorry I am not running it through batch file, but I added there how I am running it directly through CMD – Chewie Aug 15 '18 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. – Bacon Bits Aug 15 '18 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? – Chewie Aug 15 '18 at 13:14
  • Sorry I saw what is wrong, try this: nuget.exe config -set http_proxy.user=t123645. I will update the question too. But the error still occurs in powershell. – Chewie Aug 15 '18 at 13:27

2 Answers2

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
asgoodas
  • 153
  • 1
  • 1
  • 8
  • Actually I alredy have this working, but with cmd command line. What I need now is to run this code in a powershell script. – Chewie Aug 15 '18 at 11:43
  • and you should be able to do it with Invoke-Expression if you prefer: https://stackoverflow.com/a/3593445/1426007 – asgoodas Aug 15 '18 at 12:56
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
Chewie
  • 31
  • 9