Visual Studio Code
Visual Studio Code (VSC) is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS, and Linux. It comes with built-in support for JavaScript, TypeScript, and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Java, Python, PHP, Go) and runtimes (such as .NET and Unity). - definition courtesy of MS Visual Studio Code website.
NOTE: The C# extension supports limited full .NET framework debugging. It can only debug 64-bit applications with portable PDBs.
Download VSC from here
Download the installer for the platform that you want VSC to run on.
Install the application with the settings that suit your needs.
Once the application has been installed we can add plugins/extensions to support other required development capabilities (The C# extension supports limited full .NET framework debugging. It can only debug 64-bit applications with portable PDBs, visit this page to see the details).
Adding C# plugin
From VSC select the plugins icon on the left as shown in the diagram
If you have any extensions already installed they be shown in the pane that opens up here
In the search box type C#, then select install
You will now need .NET Core. Go to your search engine and search for .net core
As of writing the URL is as shown above, selecting it will take you to this page
I’m going to select the recommended version (5.0) and then download the installer for my platform
Download the installer and install the component.
Verify the dotnet install. Open a powershell or command prompt. Type the command dotnet --version
Creating a project from the command line
From powershell navigate to a folder where you want to create a new project, then type the command dotnet new console -o myfirstapp
The dotnet command line will create a new console application in the folder myfirstapp. Navigate into the folder myfirstapp and type the code . This will open up a VSC or a new VSC window if VSC is already open. Open up the file Program.cs which can be seen in the file structure on the left.
You may be prompted to install the C# extension (this will only happen if you haven’t already installed the extension)
Once the C# extension has been installed, open a terminal window within VSC and type dotnet run to run the application. The message “Hello world” should be printed in the terminal window.
Debugging your application
More often than not you will want to debug your application. Unlike Visual Studio which comes preconfigured with a debugging capability, VSC has to be configured to handle this capability. The config files needed to enable this capability can be found here.
Begin by select the “Run and Debug” button in VSC
In the “Run” view select “create a launch.json file”
An environment dropdown box will appear, select “.Net Core”. A launch.json file will be created with the following content
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
Change the content to
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Launch (console)",
"type":"coreclr",
"request": "launch",
"preLaunchTask": "my-prelaunch-task",
"program": "${workspaceFolder}/bin/Debug/net5.0/<you-app-name>.exe",
"args":[],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
}
]
}
At line 12 change the entry <your-app-name>.exe to the CSharp project name - in our case this will be myfirstapp.exe.
"program": "${workspaceFolder}/bin/Debug/net5.0/myfirstapp.exe",
Once you have saved the launch.json file, a new RUN AND DEBUG option will appear
Select the run button, the following dialog will appear - select “Configure Task”
VSC will present a dropdown box, select “Create tasks.json file from a template, then select “Others”
Replace the content in tasks.json with the following content
Make note of line 13, make sure the file name matches your CSharp project name.
Go back to Program.cs and put a breakpoint on line 9. From the “RUN AND DEBUG” dropdown select the Run button
The application will break at the point you specified, the Debug control icons will appear in the upper right of the screen, and a new pane showing VARIABLES, WATCH, CALL STACK, and BREAKPOINTS will become visible. You can now debug your application