If you're on a Mac with an Apple M1 chip, you need to install the Arm64 version of the SDK.
Check everything installed correctly
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.
If everything looks good, select the Continue button below to go to the next step.
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.
If you receive a zsh: command not found: dotnet error, make sure you opened a new terminal window. If you can't resolve the issue, use the I ran into an issue button to get help fixing the problem.
If you receive a dotnet: command not found error, make sure you opened a new terminal window. 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 -f net7.0
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 -f parameter indicates you're creating a .NET 7 application.
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 called Program.cs. By default, it already contains the necessary code to write Hello, World! to the console. The following code shows the contents of this file when the project is created:
The main file in the MyApp folder is called Program.cs. By default, it already contains the necessary code to write Hello, World! to the terminal. The following code shows the contents of this file when the project is created:
Program.cs
// See https://aka.ms/new-console-template for more informationConsole.WriteLine("Hello, World!");
Select the Continue button below to go to the next step.
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 Windows can't find the SDK when you try to create the project and you are sure you have installed the SDK, your machine might have an issue with the PATH environment variable. See this Stack Overflow post for instructions on how to diagnose and fix this issue.
If you can't resolve the issue you're having, select the I ran into an issue button below 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
// See https://aka.ms/new-console-template for more informationConsole.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 6/8/2023 12:41:27 PM
Next steps
Congratulations, you've built and run your first .NET app!
Keep learning
To keep learning general .NET skills, try our tutorials on Microsoft Learn where you'll learn about .NET, dependencies, working with files, debugging, and more:
C# is .NET's modern, innovative, open-source programming language for building all your apps. Get started by trying our C# interactive tutorials on Microsoft Learn: