21

I start to learn .Net Core. I want to write a simple 'Hello World' console application.

Unfortunately the System.Console is not available initially. This is my code:

using System;

class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello from Mac");        
    }
}

What package should I install?

FYI, I'm using Mac with VSCode and .net core rc1 update 2.

JOG
  • 5,590
  • 7
  • 34
  • 54
mehrandvd
  • 8,806
  • 12
  • 64
  • 111

3 Answers3

80

Also, just to save someone else the minor headache: Don't make the mistake of naming your project "MyThing.Console" like I did, or the Console reference in your code won't be referencing System.Console, it will be referencing your namespace looking for a type called WriteLine!

Dusty
  • 3,946
  • 2
  • 27
  • 41
14

Just add NuGet Package

System.Console

to your project. No need to muss around with project.json. That way, you also get the latest (stable) version.

One gotcha: if you name your console project Something.Console, be sure to fully qualify the path to Write, i.e.

System.Console.Write();

MonteChristo
  • 589
  • 6
  • 11
11

Make sure in your project.json system.console is referenced under frameworks:dnxcore50:dependencies

Example project.json:

{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "danny" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

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

  "dependencies": {
  },

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

  "frameworks": {
    "dnx451": { },
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Console": "4.0.0-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  }
}
JOG
  • 5,590
  • 7
  • 34
  • 54
Danny van der Kraan
  • 5,344
  • 6
  • 31
  • 41
  • 1
    Yep. That worked. Could you please provide the a sample `project.son` file content for future reference. – mehrandvd Apr 09 '16 at 12:58