在Subversion中存储ASP.NET网站的最佳实践是什么?

6
我目前在一个由多个开发人员使用Subversion进行代码分发的ASP.NET项目上工作,但它现在非常混乱。设置Subversion存储库的人已经包含了特定于他们计算机的配置文件、bin\*目录和其他类似的内容。
作为一个需要从这个存储库中检出并在我的计算机上运行它的人,我感到相当沮丧,因为花费了我一段时间来解决所有问题以使其能够成功编译。现在,我正在考虑编写一份Subversion指南文档,以便将它发送给公司的技术领袖,以便我们可以将流程标准化并避免这些问题的发生。
我希望得到指南方面的意见。以下是开始部分,希望我们可以从中获得好处:

The file structure should be set up to have third-party libraries checked in outside the build output directories (since they won't be included in the repository.) The name of this directory should be "Libraries".

No machine-specific files should be included in Subversion. Therefore, only a template of Web.config is checked in, which is customized by the developers to suit their machine. This behavior is included in Visual Studio 2010 by default and the individual configuration files (Web.Local.config) automatically have the template (Web.config) applied. The local configuration file still shouldn't be included in Subversion though, so long as it applies for a specific machine.

Solution and project files must not contain any absolute paths.

An ignore list should be set up. Start with:

'
*.user
obj
'

Example file structure for an ASP.NET 2.0 web site with a class library specific to the web site and a third-party library:

'
/trunk/
    Libraries/
        ThirdParty.dll
    MyClassLibrary/
        bin/  [Ignore]
        obj/  [Ignore]
        Properties/
            AssemblyInfo.cs
        SomeClass.cs
        MyClassLibrary.csproj
            - Holds references to third-party libraries. For example:
              ../Libraries/ThirdParty.dll
    MyWebApplication/
        bin/
            ThirdParty.dll  [Ignore; copied by build process]
            ThirdParty.dll.refresh
                - Contains "../Libraries/ThirdParty.dll"
        Default.aspx
        Default.aspx.cs
        Web.config  [Ignore]
        Web.config.template
    MySolution.sln
        - Holds list of projects.
        - Has reference information for projects.
'

An alternative to using Web.config.template would be to include a Local.config file from Web.config, but this might be less flexible.

When using a Web Application project rather than a Web Site project, the references will be stored in the project file instead of in .refresh files, so the bin/ folder will be ignored.

有人能否看到上述建议中的错误?有什么遗漏的地方吗?是否有人对忽略列表有建议?我只是暂时加了几个条目。
2个回答

7
我认为你已经迈出了很好的一步。但是,为什么不将/MyWebApplication中的整个bin文件夹忽略掉,而不是单独的文件?您不会将构建输出添加到Subversion中,对吗?我肯定认为这是一个不好的做法。
另外,如果可能的话,您可以将web.config文件添加到Subversion中,但在元素中引用一个新文件,例如:
<appSettings file="local.config">

然后让svn忽略local.config文件。这是我一直使用的方法。

但是,这只适用于每个可配置参数都在appSettings中(这也是我不喜欢提供程序模型的原因之一,因为所有提供程序都需要从connectionString元素获取连接字符串,并且您无法重新配置它们以从appSettings获取连接字符串)

编辑:troethom启发了我并指出,您还可以在单独的文件中覆盖connectionString配置设置

<connectionStrings configSource="ConnectionStrings.config"/>.

所以我会将实际的web.config文件放置在Subversion版本控制下,但是让那些在本地覆盖设置的其他文件被svn忽略。

对于2.0 Web项目,外部程序集引用仅由/bin/目录确定,因此我需要(据我所知).refresh文件位于/bin/目录中。可以让SVN忽略bin/*.dll,所以这不应该是个问题。我的意图从来不是将构建输出包含在SVN中,这正是这些指南旨在防止的。 实际上,我最初编写了导入“Local.config”文件的指南,但由于配置文件中有很多部分,我认为最好只有一个文件的副本,可以由开发人员进行配置。 - Blixt
啊 - 我忘记了那两个没有项目文件的 2.0 "网站" 项目。我从来不喜欢它们。但是你有选择权(Web 应用在 VS2005 SP1 中被重新引入)。如果你创建一个 "网站",你就没有项目文件,bin 目录成为你的引用,或者你可以创建一个 "Web 应用程序",其中引用是由项目文件定义的,你可以忽略整个 bin 文件夹。 但是我没有在 svn 中放置 "网站" 项目的经验。 - Pete
Pete,你也可以将连接字符串放在单独的配置文件中(除非你仍在使用.NET 1.1)。只需使用<connectionStrings configSource="ConnectionStrings.config"/>即可。 - Troels Thomsen
我知道两种扩展配置的方法,但它们仍然只是 appSettingsconnectionStrings... 在开发本地时,可能需要更改 Web.config 文件中的许多其他部分,因此我认为我会坚持使用模板。 - Blixt
1
顺便提一下,VS 2010 解决了针对不同环境有多个配置文件的问题。在这里,您可以覆盖 Web 配置文件的每个部分。但是,对于已经在生产中存在的系统来说,这当然不是一个选项。 - Pete
显示剩余2条评论

1

你应该添加.refresh文件,而不是真正的DLL文件。

Visual Studio项目系统会向SCC提供程序发送应该添加到源代码控制的文件列表。AnkhSVN是一个Subversion SCC提供程序,它使用这些信息来建议添加这些文件(而不是其他文件)。

VisualSVN和其他只查看文件扩展名的Subversion客户端无法从ASP.Net获取此信息。

(请注意:如果删除.refresh文件,则Visual Studio将把DLL添加到应该提交的文件列表中)


那么,我以上提出使用.refresh文件的建议,是将DLL引用包含在ASP.NET bin文件夹中的推荐方式吗? - Blixt

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