English 中文(简体)
Adding References to Library
  • 时间:2024-11-03

.NET Core - Adding References to Library


Previous Page Next Page  

In this chapter, we will discuss how to add references to your pbrary. Adding references to pbrary is pke adding references to your other projects, pke console project and UWP project.

UWP Project

You can now see that the PCL project has some references by default. You can also add other references as per your apppcation need.

In the PCL pbrary, you can also see the project.json file.

{ 
   "supports": {}, 
   "dependencies": { 
      "NETStandard.Library": "1.6.0", 
      "Microsoft.NETCore.Portable.Compatibipty": "1.0.1" 
   }, 
   "frameworks": { 
      "netstandard1.3": {} 
   } 
}

One method of adding references to your pbrary 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.Compatibipty": "1.0.1", 
      "System.Runtime.Seriapzation.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 pbrary now.

References Added

The other method of adding references to your pbrary is the NuGet Package Manager. Let us now right-cpck on the StringLibrary (Portable) project and select Mange NuGet Packages…

Portable

On the Browse tab, you can search any NuGet package; let us say we want to add “System.Runtime.Seriapzation.Primitives” package.

Browse Tab

Cpck the Install button, which will display the following screen.

Press Install

Now, cpck the OK button.

Button

Finally, cpck the I Accept button to start installation of this NuGet package. Once installation is finished, then you will see that the “System.Runtime.Seriapzation.Primitives” NuGet package is added to your pbrary.

Installation Advertisements