10

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?

2

3 Answers 3

16

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

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

2 Comments

install works but how to uninstall package using cmd. I checked this link - learn.microsoft.com/en-us/nuget/consume-packages/…, it tells about restore and install only.
Install command doesn't add dependency in csproj. it doesn't affect packages.config instead it creates separate packages folder. Why?
16

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

4 Comments

That's why I searched google and came to this page. But not working. This project doesn't support adding package through add package message shows up. What to do? I created this project using Visual Studio 2012
@MdAshrafulIslam with such an old project you'll have to use NuGet in Visual Studio
Can we switch directory for add this package ? how to switch directory in c#
@KarthicG all the dotnet add package command does is that it adds a reference to the package in the .csproj of the project; the command does not add any files or even download the package. You will have to use something else for that.
4

There are three official ways to install NuGet package in your solutions.

enter image description here

  1. Using Package Manager Console; It includes in visual studio ide (currently only on window platform) or install nuget command line tools from nuget gallery.You can copy and paste required nuget package in package manager console in ide which starts with "Install-Package" or in command line with "nuget install ". This will add packagereference in csproj

  2. Using .Net CLI; You need to install .net command line tool which install together with .net sdk. So, you just need to copy and paste in command line or bash or terminal. This works in linux, window, mac operating systems. This will add package reference in csproj file eventually.

  3. Using PackageReference; you copy and paste reference into csproj file directly.

  4. Using Paket CLI, also another kind of cli which i have never used before.

2 Comments

I have a solution with many projects. How do I add a package to one specific project?
open .csproj file from that specific folder and copy PackageReference to .csproj.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.