什么Visual Studio文件应该被Subversion忽略以最小化冲突?

73

我正在支持一些使用Subversion进行版本控制的.Net开发人员,但我们遇到了一些问题,似乎都与Visual Studio用于管理项目、调试等方面的附加文件有关。具体来说,由于它们已经在仓库中,这些文件会导致冲突。我知道如何把它们拿出来并处理它们,但首先我需要知道“它们”是什么。

那么,Subversion可以忽略哪些文件/目录,为什么可以忽略?(也就是说这些文件是做什么用的?)

这是一个较大且相当不规则的ASP.Net网站,通过svn更新来部署网站,因此需要将IIS动态编译网站所需的文件留在仓库中。


如果您使用了一个VS插件将VS与SVN集成,那么VS本身只会将它需要添加到SVN的文件添加进去。因此,它会过滤掉不需要进行版本控制的文件。 - jussij
2
@jussij - 我发现与独立的SVN客户端相比,VS集成的SVN客户端明显不及格,这就是我提出这个问题的原因 :) - cdeszaq
我不确定你尝试了哪些插件,但作为一款基于MS-SCCI的VS插件的作者,我发现它可以让与SVN的工作变得更加容易。为什么?因为IDE控制哪些文件被放入仓库中。此外,添加、删除或移动文件都可以从IDE内部完成。最后,IDE会通过视觉反馈显示文件的状态(即文件未添加、文件过期等)。 - jussij
PS:话虽如此,我的经验仅限于VS C# WinForms项目,而VS ASP.Net项目可能会有所不同;) - jussij
我同意VC解决方案对IDE的补充非常好,但我从未发现过一个能像专用的VC客户端一样出色地管理版本的IDE VC插件(主要是因为大多数IDE的VC模型太过于通用)。此外,公正地说,我已经从SVN转向Mercurial(现在是Git),因为SVN无法满足我和我的团队在工作流方面的需求。 - cdeszaq
11个回答

85
  • bin和obj目录
  • *.user文件(MyProject.csproj.user)
  • *.suo文件

另外,如果您使用的是Visual Studio 2015,则还有.vs目录。


@plntxt 我假设当前的“packages”文件夹应该是此列表的一部分,除非有些微妙之处我没有考虑到。 - wode

49

我用过这个全局忽略模式,效果很好:

*bin *obj *suo *.user *.tmp *.TMP 
*resharper* *Resharper* *ReSharper* *.Load *.gpState 
Thumbs.db *.~m2

我正在使用 Resharper 插件,所以你可以忽略它。".~m2" 是由我的数据建模工具创建的临时文件。

更新: 感谢点赞。我最近添加了 Mac、Dreamweaver、Python 以及一些需要被忽略的 Visual Studio 文件。

*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp
*[Bb]in *obj *suo *resharp* *.user *.tmp *.TMP *Resharper*
*ReSharper* *.Load *.gpState *.NoLoad  *.~m2 *.dbmdl _notes *.cache
[Tt]est[Rr]esult [Bb]uild[Ll]og.* *.[Pp]ublish.xml *.[Cc]ache [Tt]humbs.db lint.db
*.docstates .apdisk [Ll]ogs .DS_Store *.bak *.vs

如果有人不小心将应该被忽略的文件夹或文件提交到版本库中,那么你需要手动从仓库中删除这些文件,才能让 SVN 再次忽略它们。这是因为已经在版本库中的文件会覆盖任何忽略设置。


1
看起来 *.gpState 被添加了两次。 - superjos
9
我认为全局忽略不是正确的方法。这样做会导致下一个查看你项目的人看到一堆看起来未版本化的文件,可能会意外提交它们。使用svn-ignore属性会更好,因为将来任何使用该项目的人都不会犯错,因为他们的忽略已经设置好了。 - jjathman
1
一个快速的更新,针对那些正在查看这些评论的人 - 从 SVN 1.8(于2013年发布)开始,他们添加了 svn:global-ignores 属性,它是仓库的一部分,并且与我认为 @jjathman 正在提到的本地全局忽略不同。您可以在这里阅读更多信息 SVN 1.8 发布说明 ,以及在这里 高级忽略 - prime2scope

9

虽然这是一个旧的讨论帖,但我想补充一下,你可以使用GitHub上的.gitignore示例,在这里找到,作为很好的起点。

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
*.vcxproj.filters

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

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

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

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

# Chutzpah Test files
_Chutzpah*

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

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

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

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

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# Visual Studio code coverage results
*.coverage
*.coveragexml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# 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
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# 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
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/

7
  • *.bin:二进制文件
  • *.obj:目标文件
  • *.exe:可执行文件
  • *.dll:动态链接库文件
  • *.pch:预编译头文件
  • *.user:用户设置文件
  • *.suo:解决方案用户选项文件
  • *.tlb:类型库文件
  • TestResults(VSTS单元测试目录):测试结果

6
  • 'bin'目录是一个不错的开始(正如@Kevin所说)。
  • 你最好也忽略'obj'目录。
  • *.suo和*.user最好不要纳入源代码控制。
  • *.VisualState.xml也将是个人选择。
  • TestResults.xml(如果你正在使用NUnit)

6
我认为一个更好的问题应该是“我应该向Subversion添加哪些文件?”AnkhSVN 2.0 Subversion集成会向您解决方案中的所有项目提出这个问题。(这个问题是SCC规范的关键部分之一。)然后,它只建议添加这些文件。作为用户,您可以手动添加其他文件(或标记建议的某些文件为已忽略),但这种行为使正确操作变得非常容易。大多数其他Subversion客户端没有与真正理解应该添加什么和不应该添加什么的系统交流的便利。(例如,像TortoiseSVN及其前端这样的外部客户端只能根据文件扩展名猜测。)

那么,有没有办法从 Visual Studio 之外确定这一点呢?Ankh 不满足我们所有的需求,并且由于某种原因与我们的结构不兼容,因此我们不能依赖它来完成这个任务。 - cdeszaq
与VS项目作为SCC提供程序交互的唯一方式是“作为SCC提供程序”进行交互。而且这只能从VS内部完成。如果您有特定的用例未被AnkhSVN处理,您应该在ankhsvn用户列表(或uservoice页面)上告诉我们。否则,我们无法解决太多问题:) - Bert Huijben

4
这是我的TortoiseSVN全局忽略列表:
*.suo *.resharper *.sln bin obj *.user *.suo Debug Release *.pdb test.* _ReSharper*.* *.scc *.vssscc *.vspscc

最后三个帮助您从Microsoft Visual SourceSafe过渡时使用。

3

AnkhSVN 很好地完成了仅检查项目所需文件的工作。


1
他们有没有任何地方可以查看列表? - cdeszaq
AnkhSVN 2.0不使用忽略列表。该项目提供了应添加到其SCC提供程序(在这种情况下是AnkhSVN)的列表。而AnkhSVN仅建议添加这些文件。(用户可以覆盖这些设置;但通常不应这样做) - Bert Huijben

2

我建议不要将.SDF文件提交到版本控制中。这个文件很大,如果缺失,Visual Studio会重新创建它。据我所知,这是一个用于Intellisense的数据库。


1

我可能会说任何在bin目录中的东西。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接