Once we have completed the development for our ASP.NET core application, we need to deploy the application so that it can be accessed by our users.
In any application, irrespective of whether it is the web, desktop, or mobile application, not all the functionalities have been achieved through code. In fact, you should not try to achieve everything through code.
In this chapter, you are going to learn about the following topics:
If you have built a web application using any of the previous versions of ASP.NET MVC, there will be a file by the name of Web.config
(an XML file) where you can configure all the dependencies for your application. But in ASP.NET Core, there will be no Web.config
file in your solution:
Instead, we have project.json
(a JSON file), where we will configure the dependencies for your application. Before discussing the contents of project.json
, let us discuss a bit about JSON.
JSON is an acronym of JavaScript Object Notation. It is the open standard data exchange format. It will be in human-readable text and consist of attribute/value pairs. Consider the following JSON, and let's dissect it to see what it represents:
{ "addressess": [ { "DoorNo": 16, "Street": "King Street", "areaname": "Mascot" }, { "DoorNo": 12, "Street": "High Street", "areaname": "North Sydney" } ] }
Each piece of data is an attribute value pair, separated by a colon. For example, "DoorNo": 16
tells that the value for DoorNo
variable is 16 in the first record. Each attribute value pair (sometimes called a property) is separated by a comma. For example, consider the following three properties:
"DoorNo": 16, "Street": "King Street", "areaname": "Mascot"
Each record or object is contained within a pair of curly braces. For example, the following JSON data represents a record or an object:
{ "DoorNo": 16, "Street": "King Street", "areaname": "Mascot" }
Similar records can be grouped together and could be formed as an array (of objects). Square brackets are used to represent the array in JSON format as in the following example:
"addressess": [ { "DoorNo": 16, "Street": "King Street", "areaname": "Mascot" }, { "DoorNo": 12, "Street": "High Street", "areaname": "North Sydney" } ]
If we have to represent the same data in XML format, you can do so as follows. Please note that for each piece of information, we should have a start tag and an end tag (ends with "/
"):
<addresses> <address> <DoorNo>16</DoorNo> <Street>King Street</Street> <areaname>Mascot</areaname> </address> <address> <DoorNo>12</DoorNo> <Street>High Street</Street> <areaname>North Sydney</areaname> </address> </addresses>
All of the project configuration should go into the project.json
file for the ASP.NET Core application. The following is the project.json
file that was created when using the predefined ASP.NET Core web application template:
There are different predefined nodes in this JSON file for different functionalities. Let us take some important nodes in this project.json
file and discuss them.
The dependencies
node lists all the dependencies for your ASP.NET Core application.
The following is a fragment of the dependencies
node in the ASP.NET Core application. Each dependency is an attribute value pair where the attribute represents the dependency and the value represents the version of the dependency. If you need to provide more information for the dependency, you can have a nested JSON configuration as it is in Microsoft.NETCore.App
:
"dependencies":{ "Microsoft.NETCore.App":{ "version": "1.0.0-rc2-3002702", "type": "platform" }, "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final", "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2- final",
In this node, we mention the frameworks that we depend on for the ASP.NET Core application. dotnet5.6
represents the full blown .NET framework and dnxcore50
represents the .NET Core framework containing the subset of functionalities of the complete .NET framework:
"frameworks":{ "netcoreapp1.0":{ "imports":[ "dotnet5.6", "dnxcore50", "portable-net45+win8" ] } },