Packaging your libraries for NuGet distribution
Before we learn how to create and package our own libraries, we will review how a project can use an existing package.
Referencing a NuGet package
Let's say that you want to add a package created by a third-party developer, for example, Newtonsoft.Json
, a popular package for working with the JavaScript Object Notation (JSON) serialization format.
- In Visual Studio Code, open the
AssembliesAndNamespaces
project. - Enter the following command in Terminal:
dotnet add package newtonsoft.json
- Open
AssembliesAndNamespaces.csproj
, and you will see the package reference has been added, as shown in the following markup:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="newtonsoft.json" ...