Quickstart: Install and use a package with the dotnet CLI
Article
NuGet packages contain compiled binary code that developers make available for other developers to use in their projects. For more information, see What is NuGet. This quickstart describes how to install the popular Newtonsoft.Json NuGet package into a .NET project by using the dotnet add package command.
You refer to installed packages in code with a using <namespace> directive, where <namespace> is often the package name. You can then use the package's API in your project.
The .NET SDK, which provides the dotnet command-line tool. Starting in Visual Studio 2017, the dotnet CLI automatically installs with any .NET or .NET Core related workloads.
Create a project
You can install NuGet packages into a .NET project. For this walkthrough, create a simple .NET console project by using the dotnet CLI, as follows:
Create a folder named Nuget.Quickstart for the project.
Open a command prompt and switch to the new folder.
Create the project by using the following command:
.NET CLI
dotnetnew console
Use dotnet run to test the app. You should see the output Hello, World!.
Add the Newtonsoft.Json NuGet package
Use the following command to install the Newtonsoft.json package:
.NET CLI
dotnetadd package Newtonsoft.Json
After the command completes, open the Nuget.Quickstart.csproj file in Visual Studio to see the added NuGet package reference:
Create a .NET project and learn to add packages and manage package dependencies in your project. Use the .NET Core CLI and NuGet registry to add libraries and tools to your C# applications through Visual Studio Code.