.NET Core - Package References



In this chapter, we will discuss how to add packages in your .NET Core application and how to find a specific package. We can directly go to NuGet and add package, but here we will see some other places.

Let us now go to the source code of .NET Core which is located here − https://github.com/dotnet/corefx

Source Code

In CoreFx repo, open the src folder −

CoreFx

And you will see the whole list of folders that correspond to different packages. Let us now search Json −

Json

There is another way to find your package, you probably know various types if you are familiar with .NET Framework, but the assembling of packages in .NET Core is totally different and you won’t know where that packages in.

If you know the type, you can search to reverse package search by using https://packagesearch.azurewebsites.net/

Reverse Package

Here you can enter any type of package you would like to find. Then, this site will scan NuGet and find the relevant packages for you.

Let us now search for DataContractJson.

DataContractJson

You will now see that we get the same package; let us click on the package.

package

You will now see the NuGet page; you need to confirm that you need this package. You can add this in your application using a few methods.

Let us open the project.json file.

{ 
   "version": "1.0.0-*", 
   "buildOptions": { 
      "emitEntryPoint": true 
   }, 
   "dependencies": { 
      "Microsoft.NETCore.App": { 
         "type": "platform", 
         "version": "1.0.1" 
      } 
   }, 
   "frameworks": { 
      "netcoreapp1.0": { 
         "imports": "dnxcore50" 
      } 
   } 
} 

This is the new project format and inside this file you will see the dependencies section. Let us add a new dependency as shown below.

{ 
   "version": "1.0.0-*", 
   "buildOptions": { 
      "emitEntryPoint": true 
   }, 
   "dependencies": { 
      "Microsoft.NETCore.App": { 
         "type": "platform", 
         "version": "1.0.1" 
      }, 
      "System.Runtime.Serialization.Json": "4.0.2" 
   }, 
   "frameworks": { 
      "netcoreapp1.0": { 
         "imports": "dnxcore50" 
      } 
   } 
}

Now if you look at your references, then you will see that System.Runtime.Serialization.Json package is added to your project.

Run

Another way is to go to the NuGet Manager and browse the package you want to add.

Browse Package
Advertisements