DEV Community

Captain Iminza
Captain Iminza

Posted on

1

Create a .NET console application using Visual Studio Code

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

  1. Open Visual Studio Code and select File>Open Folder.
  2. In the dialog box that opens, select a folder where you want to create the app and click Select Folder.
  3. In Visual Studio Code, select View>Terminal to open the integrated terminal.
  4. 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.

  1. Navigate into the newly created HelloWorld folder:

cd HelloWorld

This command opens the current folder in Visual Studio Code.

  1. 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

  1. 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.
  2. SelectDebug>Start Debugging or press F5 to run the app with the debugger attached.
  3. 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

  1. To modify the app, change the text "Hello World!" to something else in Program.cs and save the file.
  2. Run the app again by pressing F5 or selectingDebug>Start Debugging.
  3. 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:...

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay