Run C# Console Application on Visual Studio Code Editor on Windows

18,554

Solution 1

Navigate to the folder you want to create the console app in. In VSCode, use Ctrl + ` to open the terminal window or go to View and select Integrated Terminal. Now type the following below.

  1. dotnet new console
  2. dotnet restore
  3. dotnet run

Solution 2

The best way at this present time to create a console application is to create a DNX style Console Application.

I would advise that you download and install the generator-aspnet Yeoman generator and use that to generate a DNX Console application. Once you've got generator-aspnet installed, in your terminal/console app type yo aspnet and select Console Application.

Here's a thorough guide to creating a DNX Console application which will work with VS Code: http://docs.asp.net/en/latest/dnx/console.html

Solution 3

I was trying to get a 'hello world' set up using visual studio code and c# on mac/osx.

the way I did it was as follows:

  1. Install VS Code and the c# extension

  2. Here (https://www.microsoft.com/net/core#macos) are instructions for installing dotnet core using brew:

    • Install OpenSSL brew update brew install openssl ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/ ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
    • Install dotnet core pkg: https://go.microsoft.com/fwlink/?LinkID=827526
  3. create a folder somewhere and in that folder run dotnet new

  4. Go into vs code and open the folder to get the project loaded

  5. open the terminal in that folder and run dotnet run

To create run as a task

  • CMD + shift + P then type task

  • select the Task: Configure Task Runner option

  • in the tasks.json file after the build task, add the following:

{ "taskName":"run", "args": [ "${workspaceRoot}/project.json" ] }

Share:
18,554

Related videos on Youtube

Ivan Kononenko
Author by

Ivan Kononenko

Updated on September 16, 2022

Comments

  • Ivan Kononenko
    Ivan Kononenko over 1 year

    Is there any way to create (from scratch) and run simple C# Console app in VSCode editor. ? Can you please provide step-by-step instruction how I can do that? What kind of files I must to include (except HelloWolrd.cs obviously)? What kind of commands I must to execute?

  • Will L
    Will L over 8 years
    @e4c5 Done. Have updated the answer to provide the most important bit. Also, I feel as though my initial answer was entirely valid as creating a simple DNX Console application to be used with VS Code will likely never change in the future!
  • e4c5
    e4c5 over 8 years
    Thank, you. I have upvoted. I was just pointing out the stackoverflow policy.
  • arichards
    arichards over 6 years
    Short, sweet, basically native--but I had to install .NET Core SDK first. Found here: microsoft.com/net/core#windowscmd .
  • BinaryJoe01
    BinaryJoe01 about 6 years
    Thanks for keeping it simple and to the point. @arichards Thank you for the link. When you install .NET Core SDK make sure to close your terminal/editor before running the dotnet commands in the answer above.