Back To FAQ

ASP.NET Core - project.json

The project.json file includes settings for an application which is used by .NET Core CLR (runtime) to determine how to run an application.

The following is a project.json file included by default when we create an empty ASP.NET Core web application.

project.json
{
    "dependencies": {
        "Microsoft.NETCore.App": {
            "version": "1.0.1",
            "type": "platform"
        },
        "Microsoft.AspNetCore.Diagnostics": "1.0.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "microsoft.aspnetcore.staticfiles": "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 you can see in the above project.json file, the different settings are included in the form of properties and its values in JSON format. You can add many other settings as per your need in the project.json for your application. Visual Studio provides intellisense support for all kinds of possible settings as shown below.

Intellisense Support in project.json

Let's have an overview of each setting.

dependencies

"dependencies": {
    "Microsoft.NETCore.App": {
        "version": "1.0.1",
        "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "microsoft.aspnetcore.staticfiles": "1.0.0"
}

ASP.NET Core application is actually a bunch of server-side and client-side packages and frameworks. The "dependencies" setting includes list of all the NuGet server-side packages used in the application. The references folder shows these installed NuGet packages as shown below.

References
Note:
You need to include only top level packages that you want to use in your application. Visual Studio automatically installs and manages other dependencies required for a package.

We can directly write the package name in the project.json that we want to use. Visual Studio supports intellisense for all the packages and its versions. For example, to add ASP.NET Core MVC package, we can start writing package name "Microsoft.aspnetcore." and we will get intellisense as shown below.

Add Dependencies in project.json

Select the package and the appropriate version of the package. Once included, Visual Studio automatically restores and adds newly added package to the application.

Restoring Packages

Once restored, the references folder shows the package in the listing as shown below.

Restored Package

Thus, we can add new packages in the dependencies settings.

We may also add new packages by right clicking on project in the solution explorer -> select Manage NuGet Packages.. as shown below.

Project.json
Note:
NuGet packages for all ASP.NET Core applications are stored in the central location. On Windows platform, it is located in C:\Users\{username}\ .nuget\packages folder.

tools

"tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}

The tools settings adds extra commands to be executed by the .NET Core CLR. The above "Microsoft.AspNetCore.Server.IISIntegration.Tools" adds commands related to IIS so that .NET Core CLR can execute some extra commands such as publish command to publish an application for IIS as explained in the below section.

scripts

"scripts": {
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}

The scripts settings includes commands to be executed on certain actions such as precompile, postcompile, prepublish, postpublish etc. The above scripts settings includes commands to be executed after publishing with dotnet publish command. This command can only be executed if you have included IISIntegrations tools in the tools section.

We may also add dotnet bundle command to bundle all the scripts as below.

"scripts": {
        "prepublish": ["dotnet bundle"],
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    }

To include the above bundle command, we first need to include BundlerMinifier tool in the tools section as below.

"tools": {
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
        "BundlerMinifier": "2.0.238"
    }

frameworks

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

The frameworks settings indicates the version of .NET framework an application is going to use. The .NET core CLR will use this information to build and run the application.

buildOptions

"buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
}

The buildOptions section includes different build options. The emitEntryPoint indicates to .NET Core runtime that this application includes an entry point in the form of static main method. The preserveCompilationContext setting is used to preserve assemble and other reference data to allow for the runtime configuration.

runtimeOptions

"runtimeOptions": {
        "configProperties": {
            "System.GC.Server": true
        }
    }

The runtimeOptions settings includes configurations for the runtime. The option "System.GC.Server":true indicates to use garbage collection.

publishOptions

"publishOptions": {
        "include": [
            "wwwroot",
            "web.config"
        ]
    }

The publishOptions includes settings related to publishing. For example, above include settings indicates which folders and files to publish, other folders and files will not be published. In the MVC application, you may include Views folder to be published.