Project Setup for .NET Desktop Applications
This guide walks you through creating a new .NET Desktop project, configuring essential settings, and preparing the solution for development.
1. Create a New Project
Open Visual Studio and select File > New > Project. Choose the appropriate template:
dotnet new winforms -n MyWinFormsApp
dotnet new wpf -n MyWpfApp
2. Solution Structure
A recommended folder layout ensures maintainability:
MySolution/
├── src/
│ ├── MyWinFormsApp/
│ │ ├── Properties/
│ │ ├── Forms/
│ │ └── MyWinFormsApp.csproj
│ └── MyWpfApp/
│ ├── Views/
│ ├── ViewModels/
│ └── MyWpfApp.csproj
├── tests/
│ └── MyWinFormsApp.Tests/
│ └── MyWinFormsApp.Tests.csproj
└── docs/
└── README.md
3. Target Framework
Update the <TargetFramework>
element in the project file to match the desired .NET version.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
4. NuGet Packages
Install common packages via the Package Manager Console or dotnet add package
:
dotnet add package Microsoft.Extensions.Logging
dotnet add package CommunityToolkit.Mvvm
dotnet add package Serilog
dotnet add package Microsoft.Data.SqlClient
5. Code Style & Formatting
Enable .editorconfig for consistent formatting.
# .editorconfig
root = true
[*.cs]
dotnet_style_qualification_for_field = false:suggestion
csharp_new_line_before_open_brace = all
csharp_space_after_keywords_in_control_flow_statements = true
6. Build & Run
Use the following commands from the solution root:
dotnet build
dotnet run --project src/MyWinFormsApp/MyWinFormsApp.csproj
7. Version Control
Add a .gitignore
tailored for .NET projects:
# .gitignore
bin/
obj/
*.user
*.vs/
*.suo
*.pdb
*.cache
For more details, see the Deployment guide.