Create Your First ASP.NET Core Project
This guide will walk you through the essential steps to create a new ASP.NET Core web application project using the .NET CLI (Command Line Interface).
Prerequisites
- .NET SDK installed (version 6.0 or later recommended).
- A code editor or IDE (e.g., Visual Studio, VS Code).
Step-by-Step Project Creation
Open Your Terminal or Command Prompt
Navigate to the directory where you want to create your project. You can use the cd
command to change directories.
cd path/to/your/projects/directory
Create the Project
Use the dotnet new
command followed by the project template name. For a web application, we'll use the webapp
template. The -o
flag specifies the output directory (project name).
dotnet new webapp -o MyAspNetCoreApp
Replace MyAspNetCoreApp
with your desired project name. This command will create a new folder with that name and generate the necessary project files inside.
Navigate into the Project Directory
Change your current directory to the newly created project folder.
cd MyAspNetCoreApp
Restore Dependencies
Run the following command to download and install any required NuGet packages and project dependencies.
dotnet restore
Run the Application
Execute the application using the dotnet run
command.
dotnet run
The output will indicate that the application is listening on one or more URLs (typically https://localhost:7xxx
and http://localhost:5xxx
). Open your web browser and navigate to one of these URLs to see your running ASP.NET Core application.
Project Structure Overview
After creating the project, you'll find a structure similar to this (depending on the exact template used):
MyAspNetCoreApp/
(Root project folder)Pages/
: Contains Razor Pages.wwwroot/
: Static files like CSS, JavaScript, and images.appsettings.json
: Application configuration settings.Program.cs
: The application's entry point.Startup.cs
(in older .NET versions) or configuration withinProgram.cs
: Configures application services and the request pipeline.MyAspNetCoreApp.csproj
: The project file defining dependencies and build information.
Next Steps
Congratulations! You've successfully created your first ASP.NET Core project. From here, you can start building your web application by adding new pages, controllers, models, and configuring services.
- Explore Razor Pages or MVC controllers.
- Learn about routing and middleware.
- Integrate data access and databases.