A Step-by-Step Plan to Clean Up Your `.csproj`
 
            When you're ready to revisit cleaning up your .csproj, this efficient step-by-step plan ensures you clean house without removing anything critical.
🔹 Step 1: Backup Before Making Changes
🛑 Always back up before editing your project file.
- Copy the .csprojfile to a safe location.
- (Optional) Commit your current state to Git for easy rollback.
🔹 Step 2: Identify Unused Items
We’ll detect and remove unused packages, content entries, and redundant Compile Include lines.
✅ 1. Remove Unused NuGet Packages
Use the Package Manager Console:
dotnet list package --outdated
- Review outdated or unused dependencies.
- Remove unused ones with:
dotnet remove package <PackageName>
🧹 Common culprits: legacy UI packages like Bootstrap 3, old jQuery versions, or unused testing libraries.
✅ 2. Check for Unnecessary <Content Include> Entries
Auto-included content doesn't need to be declared manually.
dotnet msbuild -preprocess | findstr "Content Include"
- Remove any <Content Include>lines that are picked up automatically (especially fromwwwroot/,Scripts/,Styles/, etc.).
✅ 3. Check for Redundant <Compile Include> Entries
Code files under folders like Models/ or Data/ are auto-included in SDK-style projects.
dotnet msbuild -preprocess | findstr "Compile Include"
- Clean up unnecessary <Compile Include>directives in.csproj.
🔹 Step 3: Test After Each Change
Don't change everything at once. For each cleanup type:
1. Remove a set of entries.
2. Run:
dotnet build
3. If it builds successfully: ✅ Commit.
4. If errors appear: 🔄 Revert and investigate.
Repeat this for each of:
- Package References
- Content Includes
- Compile Includes
🔹 Step 4: Optimize and Maintain
After a clean-up:
- ✅ Keep .csprojlean by default
- 🧼 Periodically run:
dotnet list package
- 🔁 Revisit .csprojafter major .NET upgrades
🔥 Cleanup Summary
| Step | Action | 
|---|---|
| 1️⃣ | Backup .csprojor commit to Git | 
| 2️⃣ | Remove unused NuGet packages | 
| 3️⃣ | Remove unnecessary <Content Include>entries | 
| 4️⃣ | Remove redundant <Compile Include>entries | 
| 5️⃣ | Rebuild and commit after each change | 
| 6️⃣ | Keep tidy and revisit per .NET version | 
💡 Cleaning your .csproj keeps your project easier to maintain and understand—especially for new devs joining your codebase. Let me know if you want a custom script or checklist to automate this process.