我应该将哪些C#项目文件纳入版本控制?

21

我有一个项目,因为只有Express版本的Perforce版本控制系统,所以需要手动管理它。 我想知道哪些文件应该在版本控制中排除,因为锁定许多文件可能会导致Visual Studio编译和调试问题。

到目前为止,已经包括以下内容:
.cs文件(除了属性文件夹)
.resx文件
.csproj文件

已排除:
bin文件夹
obj文件夹
属性文件夹(Properties folder)
.user文件

如果我排除了一些需要包括的文件或者有更好的方法,请告诉我。


1
如果你是学生,你可以通过DreamSpark获取VS专业版。 - SLaks
非常酷的网站,不幸的是,这是为工作而设的。 - DTown
我一直都是包含所有文件,从未注意到任何问题。 - Brandi
1
@brandi,你真的不需要将bin文件夹纳入源代码控制。 - RYFN
@brandi,由于 bin 和 obj 文件夹被标记为只读,导致我在编译/调试源代码时遇到了困难。因此,每次想要调试源代码时,我都需要进行签出/签入操作。 - DTown
4个回答

15

同时排除以下内容:

.suo
app.config (you should commit something like app-dev.config instead)

关于 app.config:

app.config 通常包含机器特定的信息(比如数据库连接字符串、默认设置或资源路径),你不希望每次从源代码控制中检出时都覆盖这些信息。这些文件应该由部署脚本创建/复制。

当多位开发人员在一个项目上工作且每个人都有自己的数据库服务器时,这尤其令人恼火。反过来可能更加危险——如果你通过从版本控制检出来部署代码,就有可能无意中将生产环境设置为使用开发数据库,这可能会造成灾难性后果。

更新于2019-03:

我开始依赖此处提供的 .gitignore 建议,因为它似乎完全适用于我所从事的任何类型的项目:https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

截至2019-03-01,它是这样的:

## 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
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates

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

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

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

# Visual Studio 2017 auto generated files
Generated\ Files/

# 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

# Benchmark Results
BenchmarkDotNet.Artifacts/

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/

# StyleCop
StyleCopReport.xml

# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.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

# Visual Studio Trace Files
*.e2e

# 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

# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json

# 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
# Note: 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
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable 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
*.appx

# 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
orleans.codegen.cs

# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true
**/wwwroot/lib/

# 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
ServiceFabricBackup/
*.rptproj.bak

# SQL Server files
*.mdf
*.ldf
*.ndf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- Backup*.rdl

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

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

# 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 personal settings
.cr/personal

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

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config

# Tabs Studio
*.tss

# Telerik's JustMock configuration file
*.jmconfig

# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output
ASALocalRun/

# MSBuild Binary and Structured Log
*.binlog

# NVidia Nsight GPU debugger configuration file
*.nvuser

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Local History for Visual Studio
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

为什么应该排除 app.config 文件? - SLaks
3
在我的工作中,我们会检查一个名为 "app.config-template" 的文件。当你第一次从版本控制系统中(VC)检出代码时,需要将其复制到 "app.config" 文件(不包括在 VC 中),并填写相关的值。这样做可以避免开发人员从头编写整个 app.config 文件,同时也意味着他们永远不会意外地将包含个人设置的 app.config 文件提交到版本控制系统中。 - Ken
@Ken:没错,这就是我在上面提到app-dev.config时的意思。 - D'Arcy Rittich

15

您应该包括 Properties 文件夹;它包含 AssemblyInfo.cs(带有所有程序集属性)和项目的默认资源和设置文件(如果有的话)。

如果有的话,还应该包括 .sln 文件。


8

别忘了在你的应用程序中添加任何可能使用的图像、图标等。很容易忘记这些。

如果有与项目相关的任何文档 - 规格、设计、帮助文件等,请将它们放入项目的单独文件夹中,然后也包括在内。


3
如果我使用第三方DLL,我会将它们与项目一起进行版本控制,并使用旁路部署来在编译期间将DLL复制到bin文件夹中(而不是只在GAC中注册DLL)。这样做的效果是,另一个开发人员可以从源代码控制中拉取项目,并拥有他们需要成功编译和运行项目的依赖项。没有浪费时间下载和安装第三方组件,而且您可以确保每个人都在针对同一版本的第三方DLL进行开发/测试。

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