ASP.NET 5 RC1 On Linux – Part III – First App (Console)

Now that we have the VM set up, and ASP.NET 5 installed, lets do the bare minimum and create a console app.  In terminal type the following commands to create a folder for our project (you can create in an alternate location if you wish)

cd ~
mkdir Code
cd Code
mkdir ConsoleApp1
cd ConsoleApp1

Then fire up an editor, in this case I use nano (sadists can use vi)

nano

Let’s start with the C# program, enter the following code:

using System;

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

Now save the file as Program.cs

Fire up the editor again and create the project file:

{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "knarfalingus" ],
  "tags": [ "hello", "world" ],
  "projectUrl": "https://www.knarfalingus.com",
  "licenseUrl": "https://opensource.org/licenses/MIT",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
  },

  "commands": {
    "ConsoleApp1": "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

Save this file as project.json

Now we execute the following command to pull in the dependencies (Microsoft.CSharp and System.Console in this case). This will pull in quite a bit of files

dnx restore

If your project.json is incorrect in any way you will be greeted with stack traces. Scroll up and start from the top.

After all the dependencies have been pulled in you can execute the program:

dnx run

The output should be

Hello World

References : http://docs.asp.net/en/latest/dnx/console.html

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

OR

LOGIN OR REGISTER

Registered users with one approved comment can comment without moderation