Once you've installed, open a new command prompt and run the following command:
Once you've installed, open a new terminal and run the following command:
Command prompt
dotnet
If the installation succeeded, you should see an output similar to the following:
Command prompt
Usage: dotnet [options]Usage: dotnet [path-to-application]Options:-h|--help Display help.--info Display .NET information.--list-sdks Display the installed SDKs.--list-runtimes Display the installed runtimes.path-to-application:The path to an application .dll file to execute.
Got an error?
If you receive a 'dotnet' is not recognized as an internal or external command error, make sure you opened a new command prompt. If you can't resolve the issue, use the I ran into an issue button to get help fixing the problem.
Create your app
In your command prompt, run the following command to create your app:
In your terminal, run the following commands to create your app:
Command prompt
dotnet new console -o myApp
Then, navigate to the new directory created by the previous command:
Command prompt
cd myApp
What do these commands mean?
The dotnet new console command creates a new console app for you.
The -o parameter creates a directory named myApp where your app is stored and populates it with the required files.
The command cd myApp changes your current directory to the one just created for the new app.
The main file in the myApp folder is Program.cs. By default, it already contains the necessary code to write "Hello World!" to the Console.
Program.cs
using System;namespace myApp{ class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } }}
Got an error?
If you receive a message similar to Template "Console Application" could not be created. Access to the path 'C:\Windows\System32\myApp' is denied., change your current directory to one where you have permissions to create a new folder and try to run the command again. If you can't resolve the issue, use the I ran into an issue button to get help fixing the problem.
Run your app
In your command prompt, run the following command:
In your terminal, run the following command:
Command prompt
dotnet run
Congratulations, you've built and run your first .NET app!
Edit your code
Open the Program.cs file in any text or code editor, such as Notepad or Visual Studio Code. The Program.cs file is located on the newly created myApp directory.
Then, add the highlighted line after the code that prints "Hello World!", like the following:
Program.cs
using System;namespace myApp{ class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine("The current time is " + DateTime.Now); } }}
Save the Program.cs file and run your code again:
Command prompt
dotnet run
If you succeed, you should see an output similar to the following:
Command prompt
Hello World!The current time is 5/15/2021 1:38:15 PM
Next steps
Congratulations, you've built and run your first .NET app!
Keep learning
To keep learning general .NET skills, try our C# interactive tutorials on Microsoft Learn: