Install nuget package linux

Install NuGet client tools

To work with NuGet, as a package consumer or creator, you can use command-line interface (CLI) tools as well as NuGet features in Visual Studio. This article briefly outlines the capabilities of the different tools, how to install them, and their comparative feature availability.

To get started using NuGet to consume packages, see:

To get started creating NuGet packages, see:

The MSBuild CLI also provides the ability to restore and create packages, which is primarily useful on build servers. MSBuild is not a general-purpose tool for working with NuGet.

Package Manager Console commands work only within Visual Studio on Windows and do not work within other PowerShell environments.

Visual Studio

Install on Visual Studio 2017 and newer

Starting in Visual Studio 2017, the installer includes the NuGet Package Manager with any workload that employs .NET. To install separately, or to verify that the Package Manager is installed, run the Visual Studio installer and check the option under Individual Components > Code tools > NuGet package manager.

Install on Visual Studio 2015 and older

NuGet Extensions for Visual Studio 2013 and 2015 can be downloaded from https://dist.nuget.org/index.html.

For Visual Studio 2010 and earlier, install the «NuGet Package Manager for Visual Studio» extension. Note, if you can’t see the extension in the first page of search results, try changing the Sort By dropdown to «Most Downloads», or an alphabetical sort.

CLI tools

You can use either the dotnet CLI or the nuget.exe CLI to support NuGet features in the IDE. The dotnet CLI is installed with some Visual Studio workloads, such as .NET Core. The nuget.exe CLI must be installed separately as described earlier.

The two NuGet CLI tools are dotnet.exe and nuget.exe . See feature availability for a comparison.

  • To target .NET Core or .NET Standard, use the dotnet CLI. The dotnet CLI is required for the SDK-style project format, which uses the SDK attribute.
  • To target .NET Framework (non-SDK-style project only), use the nuget.exe CLI. If the project is migrated from packages.config to PackageReference, use the dotnet CLI.

dotnet.exe CLI

The .NET Core 2.0 CLI, dotnet.exe , works on all platforms (Windows, Mac, and Linux) and provides core NuGet features such as installing, restoring, and publishing packages. dotnet provides direct integration with .NET Core project files (such as .csproj ), which is helpful in most scenarios. dotnet is also built directly for each platform and does not require you to install Mono.

  • On developer computers, install the .NET Core SDK. Starting in Visual Studio 2017, the dotnet CLI is automatically installed with any .NET Core related workloads.
  • For build servers, follow the instructions on Using .NET Core SDK and tools in Continuous Integration.
Читайте также:  Mysql starting server linux

To learn how to use basic commands with the dotnet CLI, see Install and use packages using the dotnet CLI.

nuget.exe CLI

The nuget.exe CLI, nuget.exe , is the command-line utility for Windows that provides all NuGet capabilities; it can also be run on Mac OSX and Linux using Mono with some limitations.

To learn how to use basic commands with the nuget.exe CLI, see Install and use packages using the nuget.exe CLI.

Windows

NuGet.exe 5.0 and later require .NET Framework 4.7.2 or later to execute.

  1. Visit nuget.org/downloads and select NuGet 3.3 or higher (2.8.6 is not compatible with Mono). The latest version is always recommended, and 4.1.0+ is required to publish packages to nuget.org.
  2. Each download is the nuget.exe file directly. Instruct your browser to save the file to a folder of your choice. The file is not an installer; you won’t see anything if you run it directly from the browser.
  3. Add the folder where you placed nuget.exe to your PATH environment variable to use the CLI tool from anywhere.

macOS/Linux

Behaviors may vary slightly by OS distribution.

  1. Install Mono 4.4.2 or later.
  2. Execute the following command at a shell prompt:
# Download the latest stable `nuget.exe` to `/usr/local/bin` sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe 
# Create as alias for nuget alias nuget="mono /usr/local/bin/nuget.exe" 

Use nuget update -self on Windows to update an existing nuget.exe to the latest version.

The latest recommended NuGet CLI is always available at https://dist.nuget.org/win-x86-commandline/latest/nuget.exe . For compatibility purposes with older continuous integration systems, a previous URL, https://nuget.org/nuget.exe currently provides the deprecated 2.8.6 CLI tool.

Feature availability

Feature dotnet CLI nuget CLI (Windows) nuget CLI (Mono) Visual Studio (Windows) Visual Studio for Mac
Search packages
Install/uninstall packages ✔(1)
Update packages
Restore packages ✔(2)
Manage package feeds (sources)
Manage packages on a feed
Set API keys for feeds
Create packages(3) ✔(4)
Publish packages
Replicate packages
Manage global-package and cache folders
Manage NuGet configuration

(1) Does not affect project files; use dotnet.exe instead.

(2) Works only with packages.config file and not with solution ( .sln ) files.

(3) Various advanced package features are available through the CLI only as they aren’t represented in the Visual Studio UI tools.

(4) Works with .nuspec files but not with project files.

Upcoming Features

If you’d like to preview upcoming NuGet features, install a Visual Studio Preview, which works side-by-side with stable releases of Visual Studio. To report problems or share ideas for previews, open an issue on the NuGet GitHub repository.

Developers working on Windows can also explore the NuGet Package Explorer, an open-source, stand-alone tool to visually explore, create, and edit NuGet packages. It’s very helpful, for example, to make experimental changes to a package structure without rebuilding the package.

Feedback

Submit and view feedback for

Источник

Install and manage NuGet packages with the dotnet CLI

You can use the dotnet CLI tool on Windows, macOS, or Linux to easily install, uninstall, and update NuGet packages in .NET projects and solutions. This article describes the most common dotnet CLI commands for managing NuGet packages.

The dotnet CLI runs on .NET, .NET Core, .NET Standard SDK-style projects, and any other SDK-style projects, for example those that target .NET Framework. For more information, see .NET project SDKs.

For most commands, the CLI tool looks for a project file in the current directory, unless a different project file is specified as an optional switch in the command. For a complete list of commands and their arguments, see dotnet CLI commands.

Prerequisites

  • The .NET Core SDK, which provides the dotnet command-line tool. Starting in Visual Studio 2017, the dotnet CLI automatically installs with all .NET and .NET Core related workloads.

Install or update a package

The dotnet add package command adds a package reference to the project file, and then runs dotnet restore to install the package.

  1. Open a command line and switch to the directory that contains your project file.
  2. Use the following command to install a NuGet package:
dotnet add package Newtonsoft.Json 

Install a specific version of a package

The dotnet add package command installs the latest version of the package unless you specify a different version.

To install a specific version of a NuGet package, use the optional -v or —version switch:

For example, to add version 12.0.1 of the Newtonsoft.Json package, use this command:

dotnet add package Newtonsoft.Json --version 12.0.1 

List package references

List the package references and versions for your project by using the dotnet list package command:

Remove a package

Use the dotnet remove package command to remove a package reference from the project file.

For example, to remove the Newtonsoft.Json package, use the following command:

dotnet remove package Newtonsoft.Json 

Restore packages

The dotnet restore command restores packages that the project file lists with . For more information, see PackageReference in project files.

.NET Core 2.0 and later dotnet build and dotnet run commands restore packages automatically. As of NuGet 4.0, dotnet restore runs the same code as nuget restore .

To restore a package with dotnet restore :

  1. Open a command line and switch to the directory that contains your project file.
  2. Run dotnet restore .

Next steps

Источник

Установка пакетов NuGet и управление ими с помощью dotnet CLI

Средство dotnet CLI в Windows, macOS или Linux можно использовать для легкой установки, удаления и обновления пакетов NuGet в проектах и решениях .NET. В этой статье описываются наиболее распространенные команды dotnet CLI для управления пакетами NuGet.

Интерфейс командной строки dotnet выполняется в проектах в стиле пакета SDK для .NET, .NET Core, .NET Standard и любых других проектах в стиле пакета SDK, например тех, которые предназначены для платформа .NET Framework. Дополнительные сведения см. в разделе Пакеты SDK для .NET.

Для большинства команд средство CLI ищет файл проекта в текущем каталоге, если в команде не указан другой файл проекта. Полный список команд и их аргументов см. в командах dotnet CLI.

предварительные требования

  • Пакет SDK для .NET Core, который предоставляет программу командной строки dotnet . Начиная с Visual Studio 2017, dotnet CLI автоматически устанавливает все рабочие нагрузки , связанные с .NET и .NET Core.

Установка или обновление пакета

Команда dotnet add package добавляет ссылку на пакет в файл проекта, а затем запускается dotnet restore для установки пакета.

  1. Откройте командную строку и перейдите в каталог, в котором находится файл проекта.
  2. Выполните следующую команду для установки пакета NuGet:
dotnet add package Newtonsoft.Json 

Установка определенной версии пакета

Команда dotnet add package устанавливает последнюю версию пакета, если не указать другую версию.

Чтобы установить определенную версию пакета NuGet, используйте необязательный -v параметр или —version параметр:

Например, чтобы добавить версию 12.0.1 пакета Newtonsoft.Json , воспользуйтесь следующей командой:

dotnet add package Newtonsoft.Json --version 12.0.1 

Вывод списка ссылок на пакеты

Выведите список ссылок и версий пакета для проекта с помощью команды пакета dotnet list :

Удаление пакета

Чтобы удалить ссылку на пакет из файла проекта, воспользуйтесь командой dotnet remove package.

Например, чтобы удалить Newtonsoft.Json пакет, используйте следующую команду:

dotnet remove package Newtonsoft.Json 

Восстановление пакетов

Команда dotnet restore восстанавливает пакеты, с которыми перечисляется файл проекта. Дополнительные сведения см. в разделе PackageReference в файлах проекта.

.NET Core 2.0 и более поздних версий dotnet build и dotnet run команды автоматически восстанавливают пакеты. По состоянию на NuGet 4.0 выполняется тот же код, dotnet restore что и nuget restore .

Восстановление пакета с помощью dotnet restore :

  1. Откройте командную строку и перейдите в каталог, в котором находится файл проекта.
  2. Выполните команду dotnet restore .

Дальнейшие действия

Источник

Оцените статью
Adblock
detector