Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Nuget package using windows command line in C# project?

I have downloaded NuGet version - 5.1.0 and tried to install one of the package - log4net using cmd. it failed. below is error -

Microsoft Windows [Version 10.0.19042.1348] (c) Microsoft Corporation. All rights reserved.

D:\Personal\ConsoleApplication1\ClassLibrary1>"D:\Personal\ConsoleApplication1\nuget_1\nuget.exe" install-package log4net Unknown command: 'install-package' NuGet.CommandLine.CommandLineException: Unknown command: 'install-package' at NuGet.CommandLine.CommandManager.GetCommand(String commandName) at NuGet.CommandLine.CommandLineParser.ParseCommandLine(IEnumerable`1 commandLineArgs) at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

D:\Personal\ConsoleApplication1\ClassLibrary1>

Here, ClassLibrary1 is C# project where I have to add log4net package. I don't want to use NuGet Package Manager Console option available in Visual Studio.

Did I write correct command?

like image 383
SSD Avatar asked Dec 03 '22 17:12

SSD


2 Answers

Install-Package is how you install via Visual Studio. The cmdlet to install a package via the CLI is nuget install <Package-Name>.

Please see this Microsoft Doc for reference: https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-nuget-cli

like image 182
Daniel Avatar answered Dec 26 '22 07:12

Daniel


For those that want the package added to their project file (rather than a bunch of files in a directory) use:

dotnet add package <PACKAGE_NAME>

this will only work if you have the dotnet command-line tool installed (obtained by installing the .NET Core SDK).

More info can be found here: https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-dotnet-cli

like image 26
somethingRandom Avatar answered Dec 26 '22 07:12

somethingRandom