Creating Your First .NET Project
Level: Beginner
- Project templates available in .NET
- Creating console, web, and API projects
- Project folder structure
- Understanding csproj files
- Running and testing projects
- Common project types
Project Templates
.NET includes templates for different application types.
View available templates:
dotnet new list
Most common:
| Template | Purpose | Command |
|---|---|---|
| console | Command-line app | dotnet new console |
| web | ASP.NET Core web app | dotnet new web |
| webapi | REST API | dotnet new webapi |
| classlib | Reusable library | dotnet new classlib |
| xunit | Unit tests | dotnet new xunit |
Create Console Application
Simplest project type.
mkdir SchoolManagementApp
cd SchoolManagementApp
dotnet new console -n SchoolApp
cd SchoolApp
Structure:
SchoolApp/
├── bin/ → Compiled output
├── obj/ → Build cache
├── Program.cs → Main code
└── SchoolApp.csproj → Project file
Run it:
dotnet run
Output:
Hello, World!
Create Web Application
For web pages (razor).
dotnet new web -n SchoolWeb
Includes:
- Program.cs (configuration)
- wwwroot (static files)
- Pages folder
Create Web API
For REST APIs.
dotnet new webapi -n SchoolAPI
Includes:
- Controllers folder
- Sample API endpoint
- Swagger documentation
This is what you'll use for School Management API.
Project File (.csproj)
Every .NET project has a .csproj file.
Example SchoolAPI.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
</ItemGroup>
</Project>
TargetFramework: .NET 8.0
PackageReference: Dependencies (NuGet packages)
Never edit csproj manually. Use:
dotnet add package [name]
Folder Structure Best Practice
SchoolManagementAPI/
├── SchoolAPI/ → Main project
│ ├── Controllers/ → API endpoints
│ ├── Models/ → Data classes
│ ├── Data/ → Database code
│ ├── Services/ → Business logic
│ ├── Program.cs → Startup
│ └── SchoolAPI.csproj
├── SchoolAPI.Tests/ → Unit tests
├── .gitignore → Git ignore file
└── README.md → Documentation
Solution File (.sln)
Groups multiple projects.
Create solution:
dotnet new sln -n SchoolManagement
Add projects:
dotnet sln add SchoolAPI/SchoolAPI.csproj
dotnet sln add SchoolAPI.Tests/SchoolAPI.Tests.csproj
Structure:
SchoolManagement.sln → Groups projects
├── SchoolAPI/
└── SchoolAPI.Tests/
Open all projects:
dotnet build
dotnet run -p SchoolAPI
Q: How do you create a new .NET project and what files are generated?
Good Answer: "Use dotnet new [template] command. For ASP.NET Core Web API project, I run dotnet new webapi -n SchoolAPI. This creates a folder with Program.cs (application startup), SchoolAPI.csproj (project configuration and NuGet packages), Controllers folder (API endpoints), bin and obj folders (build artifacts), and wwwroot (static files). The csproj file specifies TargetFramework (what .NET version to use) and NuGet package dependencies. I can run dotnet run to start the application immediately."
Use ChatGPT, Claude, or Copilot to go deeper on Creating .NET projects. Try these prompts:
"What project templates are available in .NET?""What files does 'dotnet new webapi' create?""How do I create multiple projects in one solution?""What is the difference between console app, web app, and web api projects?"
💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.