.gitignore for Visual Studio Projects and Solution

2018-12-31 23:22发布

Which files should I include in .gitignore when using Git in conjunction with Visual Studio Solutions (.sln) and Projects?

18条回答
浅入江南
2楼-- · 2018-12-31 23:50

Here's an extract from a .gitignore on a recent project I was working on. I've extracted the ones that I believe are related to Visual Studio, including the compilation outputs; it's a cross platform project, so there are various other ignore rules for files produced by other build systems, and I can't guarantee that I separated them out exactly.

*.dll
*.exe
*.exp
*.ilk
*.lib
*.ncb
*.log
*.pdb
*.vcproj.*.user
[Dd]ebug
[Rr]elease

Perhaps this question should be Community Wiki, so we can all edit together one master list with comments about which files should be ignored for which types of project?

查看更多
与君花间醉酒
3楼-- · 2018-12-31 23:51

See the official GitHub's "Collection of useful .gitignore templates".

The .gitignore for Visual Studio can be found here:
https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

查看更多
只若初见
4楼-- · 2018-12-31 23:51

Late to the party here, but I also find that I use the following. Some may only be useful for hiding sensitive files when pushing to a public remote.

#Ignore email files delivered to specified pickup directory
*.eml

#Allow NuGet.exe (do not ignore)
!NuGet.exe

#Ignore WebDeploy publish profiles
*.Publish.xml

#Ignore Azure build csdef & Pubxml files
ServiceDefinition.build.csdef
*.azurePubxml

#Allow ReSharper .DotSettings (for non-namespace-provider properties)
!*.csproj.DotSettings

#Ignore private folder
/Private/
查看更多
大哥的爱人
5楼-- · 2018-12-31 23:51

I understand this is an old question, still sharing an information. In Visual Studio 2017, you can just right click on the solution file and select Add solution to source control

enter image description here

This will add two files to your source folder.

  1. .gitattributes
  2. .gitignore

This is the easiest way I guess.

查看更多
低头抚发
6楼-- · 2018-12-31 23:53

For those interested in what Microsoft thinks should be included in the gitignore, here's the default one which Visual Studio 2013 RTM automatically generates when creating a new Git-Repository:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf


#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

See: Add a default .gitignore file on MSDN

查看更多
泪湿衣
7楼-- · 2018-12-31 23:53

In Visual Studio 2015 Team Explorer > Local Git Repositories > Project > Settings > Git > Repository Settings > Ignore & Attribute Files.You can add .gitignore file with items should be ignored in visual studio solutions by default. enter image description here

enter image description here

查看更多
登录 后发表回答