Your First ASP.NET Core Application
This module will guide you through setting up your development environment and creating your first ASP.NET Core web application. We'll cover the essential tools and concepts to get you up and running quickly.
Step 1: Install .NET SDK
The .NET SDK is the core component for developing .NET applications. It includes the compiler, the runtime, and various command-line tools.
- Go to the official .NET download page.
- Download and install the latest LTS (Long-Term Support) or Current version of the .NET SDK for your operating system (Windows, macOS, or Linux).
After installation, open your terminal or command prompt and verify the installation by running:
dotnet --version
Step 2: Create a New Web Project
ASP.NET Core provides command-line templates to quickly scaffold new projects. We'll create a basic web application.
- Navigate to your desired project directory in the terminal.
- Run the following command to create a new Razor Pages project:
dotnet new razor -o MyAspNetCoreApp
cd MyAspNetCoreApp
This command does the following:
dotnet new razor: Creates a new project using the Razor Pages template.-o MyAspNetCoreApp: Specifies the output directory for the project (creates a folder namedMyAspNetCoreApp).cd MyAspNetCoreApp: Changes the current directory to the newly created project folder.
Step 3: Run Your Application
Now that your project is created, you can run it to see it in action.
In your terminal, from within the MyAspNetCoreApp directory, run:
dotnet run
This command will build and start your web application. You'll see output similar to this:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5001
Open your web browser and navigate to http://localhost:5000. You should see the default ASP.NET Core welcome page!
Step 4: Explore the Project Structure
Let's take a quick look at the files generated for our Razor Pages application:
Pages/: Contains your Razor Pages. Each.cshtmlfile represents a page, and its code-behind.cshtml.csfile contains the logic.wwwroot/: Contains static assets like CSS, JavaScript, and images.appsettings.json: Stores configuration settings.Program.cs: The entry point of your application. This is where the host builder is configured.MyAspNetCoreApp.csproj: The project file that defines project dependencies and build settings.
You can open this project in your favorite IDE to explore these files in detail.
Next Steps
Congratulations on creating and running your first ASP.NET Core application! You're now ready to dive deeper into specific ASP.NET Core concepts. Continue to the next modules to learn about: