Run C# Console Application on Visual Studio Code Editor on Windows
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.
dotnet new console
dotnet restore
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:
Install VS Code and the c# extension
-
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
- Install OpenSSL
create a folder somewhere and in that folder run
dotnet new
Go into vs code and open the folder to get the project loaded
open the terminal in that folder and run
dotnet run
To create run as a task
CMD
+ shift + P then type taskselect the Task: Configure Task Runner option
in the tasks.json file after the build task, add the following:
{
"taskName":"run",
"args": [
"${workspaceRoot}/project.json"
]
}
Related videos on Youtube
Ivan Kononenko
Updated on September 16, 2022Comments
-
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 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 over 8 yearsThank, you. I have upvoted. I was just pointing out the stackoverflow policy.
-
arichards over 6 yearsShort, sweet, basically native--but I had to install .NET Core SDK first. Found here: microsoft.com/net/core#windowscmd .
-
BinaryJoe01 about 6 yearsThanks 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.