Console. Write to .Net Core

I am starting to learn .Net Core. I want to write a simple Hello World console application.

Unfortunately, System.Console initially unavailable. This is my code:

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

Which package should I install?

FYI, I am using a Mac with VSCode and .net core rc1 update 2.

+5
source share
2 answers

Make sure your project.json system.console says 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" } } } } 
+10
source

Also, to save someone else in a minor headache: donโ€™t make a mistake calling your project โ€œMyThing.Consoleโ€ like me, or the Console link in your code will not link to System.Console , it will refer to your namespace looking for type called WriteLine !

+3
source

Source: https://habr.com/ru/post/1246766/


All Articles