Tuesday, October 11, 2016

Asp .Net Core Part 1 : dotnet tool and Console application


Asp .Net Core is an cross platform and open source MVC framework from Microsoft. Asp .Net core is characterized by  low memory footprint.


First let's create a Console application with Asp .Net Core.  Asp .Net Core gets  installed as a part of Visual Studio Update 3.
Asp .Net Core is not tied to Visual Studio. You can use any editor for creating Asp .Net Core Application.

Here I am going to demonstrate creating a simple Console application using dotnet tool.

 I can go to command prompt and type dotnet --help.


dotnet  is the .Net Command Line Tool.

For creating an new project we can use the comman dotnet new.


The project is having two files: Project.json and Program.cs.

Project.json file is having all the dependencies. 

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      },
      "imports": "dnxcore50"
    }
  }
}

Program.cs is having the actual code.

using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

dotnet restore command is used to restore the project with dependencies form Nuget based on the entries in Project.json,

We can see the output with dotnet run command.


No comments:

Post a Comment