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 command to create your app:
Command prompt
dotnet new webapp -o MyWebApp --no-https -f net7.0
What does this command mean?
The dotnet new command creates a new application.
The webApp parameter selects what template to use when creating your app.
The -o parameter creates a directory named MyWebApp where your app is stored.
The --no-https flag specifies not to enable HTTPS.
The -f parameter indicates you're creating a .NET 7 application.
What files were created?
Several files were created in the MyWebApp directory to give you a simple web application that is ready to run.
Program.cs contains the app startup code and middleware configuration.
The Pages directory contains some example web pages for the application.
MyWebApp.csproj defines some project settings, such as, .NET SDK version to target.
The launchSettings.json file inside the Properties directory defines different profile settings for the local development environment. A port number ranging between 5000-5300 is automatically assigned at project creation and saved on this file.
Select the Continue button below to go to the next step.
Got an error?
If you receive a message similar to Template "ASP.NET Core Web App" could not be created. Failed to create the template. Details: Access to the path 'C:\Windows\System32\MyWebApp' 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, navigate to the new directory created on the previous step:
In your terminal, navigate to the new directory created on the previous step:
Command prompt
cd MyWebApp
Then, run the following command:
Command prompt
dotnet watch
You should see an output similar to the following:
Command prompt
watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.watch : Building...Determining projects to restore...All projects are up-to-date for restore.MyWebApp -> C:\Projects\MyWebApp\bin\Debug\net6.0\MyWebApp.dllwatch : Startedinfo: Microsoft.Hosting.Lifetime[14]Now listening on: http://localhost:5055info: Microsoft.Hosting.Lifetime[0]Application started. Press Ctrl+C to shut down.info: Microsoft.Hosting.Lifetime[0]Hosting environment: Developmentinfo: Microsoft.Hosting.Lifetime[0]Content root path: C:\Projects\MyWebApp\
The dotnet watch command will build and start the app, and then update the running app whenever you make code changes. You can stop the app at any time by selecting Ctrl+C.
Wait for the app to display that it's listening on http://localhost:<port number> and for the browser to launch at that address.
Wait for the app to display that it's listening on http://localhost:<port number> and then open a browser and navigate to that address. In this example, it showed that it was listening on http://localhost:5055.
Congratulations, you've built and run your first .NET web app!
Edit your code
Open the Index.cshtml file located in the Pages directory in any text editor.
Note: Make sure you're opening the cshtml page and not the cshtml.cs page. Depending on how your system is configured, Windows might hide the file extension.
Replace all of the code with the following, then save the file. The highlighted lines of code show the changes you'll be making.
Pages/Index.cshtml
@page@model IndexModel@{ ViewData["Title"] = "Home page";}<div class="text-center"> <h1>Hello, world!</h1> <p>The time on the server is @DateTime.Now</p></div>
Once this change is saved, the dotnet watch command will apply the change to the running app and refresh it in the browser, so you can see the change in the running app.
Next steps
Now that you've got the basics, continue building your first ASP.NET app with Razor Pages using this self-guided learning module on Microsoft Learn where you will build a pizza store inventory app.
Go through the 6-part Intro to Web Development with .NET series! Here, you'll build awesome projects and learn all about Razor Pages, Minimal APIs, Blazor, and more.