Console Application in ASP.Net 5 With Visual Studio 2015

In this article we will learn how to begin work on console applications ASP.NET 5 with new templates.


ASP.NET 5 is the open-source framework for developing web applications. ASP.NET is a server-side web application framework designed for web development to make dynamic web pages. ASP.NET 5 was developed by Microsoft to permit the programmers to create dynamic web sites.

ASP.NET 5 launched with the Visual Studio 2015 Preview. In Visual Studio 2015 two new templates were included for working more effectively. There are the following two templates for ASP.NET 5:

  1. ASP.NET 5 Console Application
  2. ASP.NET 5 Class Library

Getting Started

In ASP.NET 5 we can create console applications. To create a new console application we first open Visual Studio 2015. Create it using File-> New-> Project.

Now we will select the ASP.NET 5 Console Application because we will create the console application and click on the OK button.


In the Solution Explorer many new functionalities are included compared to the previous versions of Visual Studio.

solution explorer


This is the global JavaScript object notation used for converting values to JSON. JSON can't be called or constructed. A Global.json file is used to better support projects to make project references. It contains the sources["src"] element indicating the "src" folder. The Global.json contains the following code:

  1. {  
  2.    "sources": [ "src""test" ]  
  3. }  

JSON Editor Improvement

In ASP.NET 5 Microsoft has made some improvements in the JSON editor. It contains performance improvements such as loading JSON schema asynchronously, caching of child schemas and better intellisence. In ASP.NET there are the following features included:

  • Un-minify context menu
We can right-click the JSON editor and select the Un-minify context menu to un-minfy any long arrays in the file.
  • JSON Schema validation
In ASP.NET 5 we can add a JSON schema validation feature, based on the schema that is expanded into the schema drop-down list.


The project.json file defines the project information. The project.json file is used for references and package dependencies, framework configurations, version definition, compile option, build events, run commands and package creation meta-data as well as other details. In this way, the project can be edited and run in Linux and on the MacoS machine that does not have Visual Studio. project.json contains the following code by default:

  1. {  
  2.     "version""1.0.0-*",  
  3.     "dependencies":   
  4.     {  
  5.     },  
  6.     "commands":   
  7.     {  
  8.         "run""run"  
  9.     },  
  10.     "frameworks":   
  11.     {  
  12.         "aspnet50": {},  
  13.         "aspnetcore50":   
  14.         {  
  15.             "dependencies":   
  16.             {  
  17.                 "System.Console""4.0.0-beta-22231"  
  18.             }  
  19.         }  
  20.     }  
  21. }  

The next item we seen in the Solution Explorer is Dependencies. It is a new item that was added in Visual Studio 2015 to support two open source package managers, NPM and Bower. This article provides an idea of how to use and configure Bower and NPM in detail.

Now we will write the sample for the calculator for testing the console application. This simple code will do the add, subtract, multiply and divide.

  1. using System;  
  3. namespace ConsoleApp1   
  4. {  
  5.     public class Program   
  6.     {  
  7.         public void Main(string[] args)   
  8.         {  
  9.             Console.WriteLine("Write a number for x");  
  10.             int x = Convert.ToInt32(Console.ReadLine());  
  11.             Console.WriteLine("Write a number for y");  
  12.             int y = Convert.ToInt32(Console.ReadLine());  
  13.             Console.WriteLine("// Choose a option //");  
  14.             Console.WriteLine("1 - addition");  
  15.             Console.WriteLine("2 - subtration ");  
  16.             Console.WriteLine("3 - multiplication");  
  17.             Console.WriteLine("4 - division");  
  18.             int z = Convert.ToInt32(Console.ReadLine());  
  19.             switch (z)  
  20.             {  
  21.                 case 1:  
  22.                     Console.WriteLine("///////////////////////");  
  23.                     Console.WriteLine("// Result //");  
  24.                     Console.WriteLine("///////////////////////");  
  25.                     Console.WriteLine(x + y);  
  26.                     break;  
  27.                 case 2:  
  28.                     Console.WriteLine("///////////////////////");  
  29.                     Console.WriteLine("// Result //");  
  30.                     Console.WriteLine("///////////////////////");  
  31.                     Console.WriteLine(x - y);  
  32.                     break;  
  33.                 case 3:  
  34.                     Console.WriteLine("///////////////////////");  
  35.                     Console.WriteLine("// Result //");  
  36.                     Console.WriteLine("///////////////////////");  
  37.                     Console.WriteLine(x * y);  
  38.                     break;  
  39.                 case 4:  
  40.                     Console.WriteLine("///////////////////////");  
  41.                     Console.WriteLine("// Result //");  
  42.                     Console.WriteLine("///////////////////////");  
  43.                     Console.WriteLine(x / y);  
  44.                     break;  
  45.             }  
  46.             Console.ReadKey(true);  
  47.         }  
  48.     }  
  49. }  

After writing the code now we need to execute the code and show the output screen after the execution.

I hope this article is helpful for the readers when they want to begin working in the ASP.NET 5 console applications. Thanks for reading this article.