0

I am facing a situation where nuget.exe is not being recognized by Powershell in Windows Server 2012. I am pretty sure that the environment variable has been correctly set. Yet I am getting the following error:

nuget : The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ nuget
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (nuget:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I am getting the same error even if I go to the directory where nuget.exe is present and execute nuget.

Windows CMD is showing nuget is not a recognized command, but it's working fine if I execute nuget inside a directory where nuget.exe is present.

Am I making a mistake in setting up environment variable for nuget? Please help :)

Note: I am new to dotnet tech ecosystem.

2
  • 2
    In PowerShell, if you navigate to the folder of an executable, you must prefix the name with ".\" for it to run. For example: C:\Nuget> .\nuget.exe Commented Nov 9, 2018 at 13:34
  • @boxdog it worked. Thank you for helping me and others who find themselves stuck in this situation :) Commented Nov 9, 2018 at 13:47

2 Answers 2

2

Like a lot of Unix systems, Powershell doesn't include current directory in the path. One needs to either use full path or explicitly include current directory.

Try .\nuget.exe in Nuget's directory.

As explained in the documentation,

As a security feature, PowerShell does not run executable (native) commands, including PowerShell scripts, unless the command is located in a path that is listed in the Path environment variable $env:path or unless you specify the path to the script file.

Sign up to request clarification or add additional context in comments.

1 Comment

@AdityaKrishnakant Alternatively, ensure the path to nuget.exe is included in the environment's PATH variable.
0

Your path variable should be a Semi-colon separated list of paths containing your directories: On one of my Server 2012 boxes it looks like this:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\TShell\TShell\;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\Program Files (x86)\dotnet\

which is a bit long and awkward. You should append your path to NuGet to this string and save it.

From Windows Explorer, right click on This PC => Properties. Locate Advanced system settings on the the left hand Panel. Choose the Advanced tab. Click on the Environment Variables button on the bottom right. Scroll the window down until you find the Path variable.

I usually copy and paste it to/from a text editor for ease of use.

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.