Introduction
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:
- ASP.NET 5 Console Application
- 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.
Global.json
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:
- {
- "sources": [ "src", "test" ]
- }
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:
We can right-click the JSON editor and select the Un-minify context menu to un-minfy any long arrays in the file.
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.
Project.Json
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:
- {
- "version": "1.0.0-*",
- "dependencies":
- {
- },
- "commands":
- {
- "run": "run"
- },
- "frameworks":
- {
- "aspnet50": {},
- "aspnetcore50":
- {
- "dependencies":
- {
- "System.Console": "4.0.0-beta-22231"
- }
- }
- }
- }
Dependencies
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.
- using System;
-
- namespace ConsoleApp1
- {
- public class Program
- {
- public void Main(string[] args)
- {
- Console.WriteLine("Write a number for x");
- int x = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Write a number for y");
- int y = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("// Choose a option //");
- Console.WriteLine("1 - addition");
- Console.WriteLine("2 - subtration ");
- Console.WriteLine("3 - multiplication");
- Console.WriteLine("4 - division");
- int z = Convert.ToInt32(Console.ReadLine());
- switch (z)
- {
- case 1:
- Console.WriteLine("///////////////////////");
- Console.WriteLine("// Result //");
- Console.WriteLine("///////////////////////");
- Console.WriteLine(x + y);
- break;
- case 2:
- Console.WriteLine("///////////////////////");
- Console.WriteLine("// Result //");
- Console.WriteLine("///////////////////////");
- Console.WriteLine(x - y);
- break;
- case 3:
- Console.WriteLine("///////////////////////");
- Console.WriteLine("// Result //");
- Console.WriteLine("///////////////////////");
- Console.WriteLine(x * y);
- break;
- case 4:
- Console.WriteLine("///////////////////////");
- Console.WriteLine("// Result //");
- Console.WriteLine("///////////////////////");
- Console.WriteLine(x / y);
- break;
- }
- Console.ReadKey(true);
- }
- }
- }
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.