简体   繁体   中英

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 -

在此处输入图片说明

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?

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://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-nuget-cli

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://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-dotnet-cli

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

在此处输入图片说明

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM