热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

管理网络。为VS2010和TFS中的团队配置-Managingweb.configforteamsinVS2010&TFS

WithVS2010smandatethatweb.configbeincludedintheproject,howdowealloweveryonetokeept

With VS2010's mandate that web.config be included in the project, how do we allow everyone to keep their own custom config file without getting into source control problems?

在VS2010的授权下。在项目中包含配置,我们如何让每个人都保留自己的自定义配置文件而不涉及源代码控制问题?

Previously, we would simply leave web.config out of our project, allowing everyone to keep their own local version of web.config on their machine. We moved to VS2010, and it is now forcing me to add web.config to my project in order to run debug mode. Because our project is linked to TFS, it automatically adds web.config to source control and tries to maintain it that way.

以前,我们只需要离开web。配置出我们的项目,允许每个人保留他们自己的本地版本的web。他们的机器上配置。我们搬到VS2010,现在迫使我添加网络。配置到我的项目以运行调试模式。因为我们的项目链接到TFS,它会自动添加web。配置到源代码控制,并试图以这种方式维护它。

Is there a way to run in debug mode without including web.config in your project? Or is there a better way to manage config files?

有没有一种方法可以在调试模式下运行而不包括web。配置在您的项目?还是有更好的方式来管理配置文件?

5 个解决方案

#1


32  

I hope this helps someone. I've used this methodology for the past couple of months now. This is really easy to do. I am using VS 2010 with TFS 2010. Let's break it down:

我希望这能帮助某人。在过去的几个月里,我使用了这种方法。这很容易做到。我使用VS 2010和TFS 2010。让我们分解:

  • All web config files are now "DependentOn" the "web.config"
  • 所有的web配置文件现在都“依赖”于“web.config”
  • Each developer or team needs their own "[User/Team].Debug.config"
  • 每个开发人员或团队都需要自己的“[用户/团队].Debug.config”
  • Config files should be transformed regardless if we're "Publishing" in release mode or not.
  • 无论我们是否在发布模式下“发布”,配置文件都应该被转换。

Here's how it's done:

如何做:

  1. Right-click the Web project you want to do this to and choose "Unload Project" (not "Remove Project").

    右键单击要执行此操作的Web项目并选择“卸载项目”(而不是“删除项目”)。

  2. Right-click the same Web project again (should be grayed-out now) and choose "Edit ...csproj". This will open the project in an Xml editor.

    再次右键单击相同的Web项目(现在应该是灰色的)并选择“Edit…csproj”。这将在Xml编辑器中打开项目。

  3. Scroll down until you find the section that has all the "Web.config" listings. Now, comment out all the "DependentUpon" elements in the Xml.

    向下滚动,直到找到包含所有“Web”的部分。配置”上市。现在,注释掉Xml中的所有“DependentUpon”元素。

  4. Close the Xml editor and save your changes. Next, right-click on your project again and choose "Reload". When the project reloads, you will notice that the Web.configs no longer "stack" under the "Web.config". This is necessary in order to "trick" TFS.

    关闭Xml编辑器并保存更改。接下来,再次右键单击项目并选择“Reload”。当项目重新加载时,您将注意到Web。配置不再在“Web.config”下“堆栈”。这对于“欺骗”TFS是必要的。

  5. Now, copy the "Web.config" file, paste it in the same project and rename it to "Web.base.config". This is going to be used to re-generate the Web.config each time (covered next).

    现在,复制“网络。配置文件,粘贴到同一个项目中,重命名为“Web.base.config”。这将用于重新生成Web。每次配置(下一个)。

  6. Now, select the Web.config file and go to "File --> Source Control --> Exclude Web.config from Source Control". Also, Open the Source Control Explorer (TFS Explorer view) and find the location of where your Web.config is and delete it from TFS. This is done because the Web.config will get re-generated each time you build the project (which I will cover next).

    现在,选择网络。配置文件,进入“file——>源代码控制——>排除Web”。配置从源代码控制”。另外,打开源代码控制资源管理器(TFS Explorer视图)并找到Web的位置。配置是从TFS中删除的。这是因为网络。配置将在每次构建项目时重新生成(我将在下文中介绍)。

  7. Now, we're going to create a new Build file that will help us regenerate the Web.config for any Built Type, even Debug ones (which is what the Web.config Transformed lacked to begin with). Create a new Xml file in your project and rename it to "[YourProjectName].wpp.targets". It is important to name this exactly what your project is called including all dots, dashes, etc (ex. My.Project.wpp.targets).

    现在,我们将创建一个新的构建文件,它将帮助我们重新生成Web。配置任何构建类型,甚至调试类型(这就是Web。配置转换缺少开始)。在项目中创建一个新的Xml文件,并将其重命名为“[YourProjectName].wpp.targets”。很重要的一点是,将这个项目命名为包括所有的点、dashes等(例如,my.project.wpp.target)。

  8. Now, enter the following Xml into the new file. Do not worry if it starts underlining syntax errors:

    现在,在新文件中输入以下Xml。不要担心它开始强调语法错误:

    
    
        
    
        
        
            
        
    
        
            
            
        
    
    
  9. Now, from this point on, you NEVER, NEVER edit the Web.config, it will be overwritten every time the app compiles. You only edit the "Web.base.config".

    现在,从这一点开始,你永远不会,永远不会编辑网络。配置,每次编译时都会覆盖它。只编辑“Web.base.config”。

  10. Now, let's make the Project look like it was. Right-click the Project again and "Unload" it. Now, right-click again and "Edit" it. Now, go back and un-comment all the Elements we commented out in Step #3. Also, you should add the "DependentOn" element under the "Web.base.config" element so that it will show up under the "Web.config" as well. Close and save it, then reload your project again. You should notice that all the configs are now under the "Web.config" again.

    现在,让我们让这个项目看起来是这样的。再次右键单击项目并“卸载”它。现在,再次右键单击并“编辑”它。现在,返回并取消我们在步骤#3中注释的所有元素的注释。此外,您应该在“Web.base”下添加“DependentOn”元素。配置元素,使其显示在“Web”下。配置”。关闭并保存它,然后重新加载项目。您应该注意到所有的配置现在都在“Web”下。重新配置”。

  11. At this point, you can add as many Configurations to your Project / Solution as you want. For example, I've added a Build Config called "Tim (Debug)", but the Project config is called "Tim.Debug". When I right click the "Web.config" and choose "Add Config Transforms", it now adds my "Web.Tim.Debug.config" file. You could also add configs per environment or per team.

    此时,您可以向项目/解决方案添加任意数量的配置。例如,我添加了一个名为“Tim (Debug)”的构建配置,但项目配置称为“Tim.Debug”。当我右键单击“Web”。配置“并选择”添加配置转换“,它现在添加了我的“Web.Tim.Debug”。配置文件”。您还可以为每个环境或每个团队添加配置。


It's worth noting that your individual config files are only a sub-set of the "Web.base.config" and they will be "Transformed" during any build process. To switch which Transform is going to be built during debugging, just go to the top of your solution and choose which Build Config you want. As long as you have a web.config for that Build Config, it will transform. If not, you'll get the "Web.base.config" instead.

值得注意的是,您的配置文件只是“Web.base”的子集。配置,它们将在任何构建过程中被“转换”。要切换调试期间将要构建的转换,只需转到解决方案的顶部并选择需要的构建配置。只要你有网络。对于构建配置,它将进行转换。如果没有,你就会得到“网络。base”。配置”。

NOTE: This should also work with standard Windows/WPF apps as well using the "app.config" instead.

注意:这也应该适用于标准的Windows/WPF应用程序,也可以使用“app.config”。

#2


3  

I haven't seen a good answer for managing different web.config files per developer with TFS to date.

我还没有看到管理不同网络的好办法。使用TFS为每个开发人员配置文件。

However if the issues that cause developers to require different web.config files are addressed instead, this typically results in better results regardless of the chosen version control system.

但是如果问题导致开发人员需要不同的web。相反,配置文件会被处理,无论选择的版本控制系统是什么,这通常都会带来更好的结果。

For example, less differences between developer environments will reduce Works On My Machine (WOMM) arguments and will often also reduce the configuration changes for environments beyond development (eg Test, Production) which in turn simplifies deployment and reduces annoying environment-configuration-specific bugs.

例如,开发环境之间的差异减少将减少我的机器(WOMM)参数的工作,并且通常还会减少开发(如测试、生产)之外的环境的配置更改,从而简化部署并减少恼人的环境配置特定的bug。

Depending on the nature of the configuration item, there are usually several different strategies to mitigate per-environment differences. Many of which I suspect already have answers on Stack Overflow.

根据配置项的性质,通常有几种不同的策略来减少环境之间的差异。我怀疑其中许多已经有关于栈溢出的答案。

#3


1  

Jarrett,

Jarrett,

All I have is an anecdote about how we handle the situation.

我所拥有的只是一个关于我们如何处理情况的轶事。

We have a team of 4 programmers.

我们有一个由4个程序员组成的团队。

We use a source control solution outside of VS -- TortoiseSVN. We each maintain our own local web.config which is included in the project. The project file is included in the repository, but we have the web.config set to "Ignore on commit" status.

我们在VS之外使用一个源代码控制解决方案——玳瑁。我们每个人都有自己的本地网络。配置,包含在项目中。项目文件包含在存储库中,但是我们有web。配置设置为“忽略提交”状态。

I'm not sure what source code control you are using, but subversion with Tortoise SVN (which runs outside of Visual Studio) has worked great for our small team. Most of us program on two separate machines... one at the office, one at home.. so when you couple that with the fact that we have two production servers, we're comfortably dealing with 10 web.config's per project.

我不确定您正在使用什么源代码控制,但是使用玳瑁SVN(在Visual Studio之外运行)进行的subversion非常适合我们的小团队。我们大多数人在两台不同的机器上编程……一个在办公室,一个在家里。当你把这和我们有两个生产服务器这两个事实结合起来,我们就可以轻松地处理10个web。配置的每个项目。

With that said, you have to remember to bring over another developer's web.config file when you setup a new development computer, otherwise the solution will either not load properly, or setup a default web.config which does not contain the appropriate connection strings and app settings.

说到这里,您必须记住要引入另一个开发人员的web。设置新开发计算机时配置文件,否则解决方案将不正确加载,或设置默认web。配置不包含适当的连接字符串和应用程序设置。

And a final note: We're using IIS 7 for debugging

最后要注意的是:我们正在使用IIS 7进行调试

#4


1  

SO has a good answer for this here .. I havent checked out the multiple web.configs in VS2010 but I wonder if this was added because of the changes they did make to web.conig..

这里有一个很好的答案。我还没查过多重网络。configs在VS2010中,但是我不知道是否因为他们对web.conig.

#5


1  

I have used T4 templates to solve this. Instead of having a web.config, you have a web.tt which generates a web.config. In the web.tt file you can generate different code based on the machinename or the current user.

我使用了T4模板来解决这个问题。而不是拥有一个网络。config,你有一个网络。生成一个web.config的tt。在web。可以根据machinename或当前用户生成不同的代码。


推荐阅读
author-avatar
手机用户2502881927
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有