ASP.NET Core - Project.Json



In this chapter, we will discuss the project.json file. This file is using JavaScript object notation to store configuration information and it is this file that is really the heart of a .NET application. Without this file, you would not have an ASP.NET Core project. Here, we will discuss some of the most important features of this file. Let us double-click on the project.json file.

Double Click On Project JSon

Currently, the default code implementation in project.json file is as follows −

{
   "dependencies": {
      "Microsoft.NETCore.App": {
         "version": "1.0.0",
         "type": "platform"
      },
      "Microsoft.AspNetCore.Diagnostics": "1.0.0",
      "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
      "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
      "Microsoft.Extensions.Logging.Console": "1.0.0"
   },
   "tools": {
      "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
   },
   "frameworks": {
      "netcoreapp1.0": {
         "imports": ["dotnet5.6", "portable-net45+win8"]
      }
   },
   "buildOptions": {
      "emitEntryPoint": true,
      "preserveCompilationContext": true
   },
   "runtimeOptions": {
      "configProperties": {
         "System.GC.Server": true
      }
   },
   "publishOptions": {
      "include": ["wwwroot", "web.config" ]
   },
   "scripts": {
      "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath%
         --framework %publish:FullTargetFramework%" ]
   }
}

As we see, we have version information at the top of this file. This is the version number your application will use when you build it.

  • The version is 1.0.0, but the most important part of this file is the dependencies.

  • If your application is going to do any useful work, then you will need libraries and frameworks to do that work, such storing and retrieving data to/from a database or render complicated HTML.

  • With this version of ASP.NET Core, the dependencies are all managed via the NuGet package manager.

  • NuGet has been around the .NET space for a few years, but now the primary way to manage all your dependencies is by using libraries and frameworks that are wrapped as NuGet packages.

  • All of the top-level NuGet packages your application needs will be stored in this project.json file.

"Microsoft.AspNetCore.Diagnostics": "1.0.0", 
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 
"Microsoft.Extensions.Logging.Console": "1.0.0

You can see we have some dependencies in this file and the exact dependencies will probably change by the final release of ASP.NET. When you want to add a new dependency, say like the ASP.NET MVC framework, you easily type into this project.json file, and you will also get some IntelliSense help including not just the package name but also the version numbers as shown in the following screenshot.

IntelliSense

You can also use the UI by right-clicking on References in the Solution Explorer and then, select Manage NuGet packages. You can now see the currently installed packages.

Installed Packages

Those packages are the same ones that are in your project.json file and you can also go to the Browser and add other packages, including pre-released packages, let us say, the MVC framework installed into this project.

MVC Framework

If you install this package right now by using the Install button, then this package would be stored in project.json. The frameworks section is another important part of project.json, this section tells ASP.NET as to which of the .NET frameworks your application can use.

"frameworks": { 
   "netcoreapp1.0": { 
      "imports": [ 
         "dotnet5.6", 
         "portable-net45+win8" 
      ] 
   } 
},

In this case, you will see that "netcoreapp1.0" is the framework used in the project, you can also include the full .NET Framework which is installed when you install Visual Studio.

  • It is the same .NET Framework that is included with many versions of the Windows Operating System.

  • It is the .NET Framework that has been around for 15 years, and it includes the frameworks that do everything from web programming to desktop programming.

  • It is a huge framework that works only on Windows.

  • “netcoreapp1.0” is the .NET Core framework. It is a cross-platform framework and can work on various platforms, not just Windows but also OS X and Linux.

  • This framework has fewer features than the full .NET framework, but it does have all the features that we need for ASP.NET Core web development.

Advertisements