English 中文(简体)
.NET Core - Package References
  • 时间:2024-11-05

.NET Core - Package References


Previous Page Next Page  

In this chapter, we will discuss how to add packages in your .NET Core apppcation 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 pst 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 famipar with .NET Framework, but the assembpng 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 pke 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 cpck 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 apppcation 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.Seriapzation.Json": "4.0.2" 
   }, 
   "frameworks": { 
      "netcoreapp1.0": { 
         "imports": "dnxcore50" 
      } 
   } 
}

Now if you look at your references, then you will see that System.Runtime.Seriapzation.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