C# and .NET .gitignore Configuration

Comprehensive .gitignore for C#, .NET, and Visual Studio projects. Covers bin/obj directories, NuGet packages, user option files, and build artifacts.

Language

Detailed Explanation

C# and .NET projects produce extensive build artifacts across multiple directories. Visual Studio adds its own layer of user-specific files. The official GitHub .gitignore template for Visual Studio is one of the longest, and for good reason.

Core build directories:

  • bin/ — Compiled assemblies (.dll, .exe), debug symbols (.pdb), and runtime configuration. Each project has its own bin/Debug/ and bin/Release/ subdirectories.
  • obj/ — Intermediate compilation output including generated source, temporary assemblies, and project assets. The obj/ directory is used during the build process and should never be committed.
  • [Dd]ebug/, [Rr]elease/ — Build configuration output directories. The character class notation handles both casings.
  • x64/, x86/ — Platform-specific build output for native interop projects.

NuGet packages:

  • packages/ — Legacy NuGet packages directory (pre-PackageReference format). Modern .NET uses a global cache at ~/.nuget/packages/.
  • *.nupkg — Built NuGet package files ready for publishing.
  • *.snupkg — Symbol NuGet packages for debugging support.
  • packages.lock.json — Consider committing lockfiles for deterministic restores across environments.

Visual Studio user files:

  • *.suo — Solution user options. A binary file storing window positions, breakpoints, and open document state. The biggest source of unnecessary changes in .NET repos.
  • *.user — Project user settings containing local debug paths and personal preferences.
  • .vs/ — Visual Studio 2015+ hidden folder with IntelliSense caches, diagnostic data, and per-user settings. Can grow to several hundred megabytes.

Test and analysis output:

  • TestResults/ — Unit test execution results and coverage data from dotnet test.
  • *.coverage and *.coveragexml — Code coverage reports from Visual Studio's coverage tools.
  • BenchmarkDotNet.Artifacts/ — Performance benchmark results from BenchmarkDotNet.

What to commit: .sln (solution file), .csproj/.fsproj (project files), Directory.Build.props, global.json (SDK version pinning), and NuGet.Config (package source configuration).

Use Case

A .NET team using both Visual Studio on Windows and JetBrains Rider on macOS needs a .gitignore that handles both IDEs' metadata and the shared MSBuild output.

Try It — .gitignore Generator

Open full tool