.NET Core – Adding References to Library
”;
In this chapter, we will discuss how to add references to your library. Adding references to library is like adding references to your other projects, like console project and UWP project.
You can now see that the PCL project has some references by default. You can also add other references as per your application need.
In the PCL library, you can also see the project.json file.
{ "supports": {}, "dependencies": { "NETStandard.Library": "1.6.0", "Microsoft.NETCore.Portable.Compatibility": "1.0.1" }, "frameworks": { "netstandard1.3": {} } }
One method of adding references to your library is by typing it directly in the project.json file. As you can see that we have added some references under the dependencies section as shown in the following code.
{ "supports": {}, "dependencies": { "NETStandard.Library": "1.6.0", "Microsoft.NETCore.Portable.Compatibility": "1.0.1", "System.Runtime.Serialization.Json": "4.0.3", "Microsoft.EntityFrameworkCore": "1.1.0" }, "frameworks": { "netstandard1.3": {} } }
Let us now save this file and you will see that references are added to your library now.
The other method of adding references to your library is the NuGet Package Manager. Let us now right-click on the StringLibrary (Portable) project and select Mange NuGet Packages…
On the Browse tab, you can search any NuGet package; let us say we want to add “System.Runtime.Serialization.Primitives” package.
Click the Install button, which will display the following screen.
Now, click the OK button.
Finally, click the I Accept button to start installation of this NuGet package. Once installation is finished, then you will see that the “System.Runtime.Serialization.Primitives” NuGet package is added to your library.
”;