- .NET Core Tutorial
- .NET Core - Home
- .NET Core - Overview
- .NET Core - Prerequisites
- .NET Core - Environment Setup
- .NET Core - Getting Started
- .NET Core - Numerics
- .NET Core - Garbage Collection
- .NET Core - Code Execution
- .NET Core - Modularity
- .NET Core - Project Files
- .NET Core - Package References
- Create UWP App with .NET Core
- .NET Core - MSBuild
- .NET Core - Metapackage
- Windows Runtime & Extension SDKs
- Create .NET Standard Library
- .NET Core - Portable Class Library
- Adding References to Library
- Sharing .NET Core Libraries
- Creating a Xamarin.Forms Project
- .NET Core - PCL Troubleshooting
- .NET Core - Create a Testing Project
- Running Tests in Visual Studio
- .NET Core - Testing Library
- Managed Extensibility Framework
- .NET Core - SDK
- .NET Core - MSBuild & project.json
- Restoring and Building & MSBuild
- .NET Core - Migrations
- .NET Core Useful Resources
- .NET Core - Quick Guide
- .NET Core - Useful Resources
- .NET Core - Discussion
.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.