This tutorial shows how to create and run a .NET console application by using Visual Studio Code and the .NET CLI. Project tasks, such as creating, compiling, and running a project are done by using the .NET CLI.
Prerequisites
- Visual Studio Code
- The C# extension for Visual Studio Code
- The .NET SDK
Create the app
- Open Visual Studio Code and select File>Open Folder.
- In the dialog box that opens, select a folder where you want to create the app and click Select Folder.
- In Visual Studio Code, select View>Terminal to open the integrated terminal.
- In the terminal, enter the following command:
dotnet new console -o HelloWorld
This command creates a new console app project in a subfolder named HelloWorld. The -o parameter specifies the output directory.
- Navigate into the newly created HelloWorld folder:
cd HelloWorld
This command opens the current folder in Visual Studio Code.
- Select Program.cs to open it in the editor. This file contains the C# code that prints "Hello World!" to the console.
Run the app
- To run the app, selectView>Command Paletteand type run in the search box. Select.NET: Generate Assets for Build and Debugfrom the list of commands. This command creates a launch.json file that contains debugging configurations and a tasks.json file that contains build tasks.
- SelectDebug>Start Debugging or press F5 to run the app with the debugger attached.
- You should see "Hello World!" printed in the terminal and a message that says "The program has exited with code 0" in the debug console.
Modify the app
- To modify the app, change the text "Hello World!" to something else in Program.cs and save the file.
- Run the app again by pressing F5 or selectingDebug>Start Debugging.
- You should see your modified text printed in the terminal.
Congratulations! You've created and run your first .NET console app using Visual Studio Code and the .NET CLI. You can learn more about .NET development by following these links:...
Top comments (0)