管理在VS2010和放大器团队web.config中; TFS [英] Managing web.config for teams in VS2010 & TFS

查看:261
本文介绍了管理在VS2010和放大器团队web.config中; TFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VS2010的任务是web.config中列入的项目,我们怎么让大家保持自己的自定义配置文件,而无需进入源代码管理的问题?

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?

previously,我们就干脆离开的web.config我们的项目,让每个人都保持web.config中自己的本地版本的机器上。我们搬到了VS2010,而现在是逼着我web.config中才能运行调试模式添加到我的项目。由于我们的项目链接到TFS,它会自动添加web.config中源代码控制,并试图保持这种方式。

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.config运行?还是有更好的方法来管理配置文件?

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?

推荐答案

我希望这可以帮助别人。我现在已经用这种方法在过去的几个月。这是很容易做到。我使用VS 2010与2010年TFS让我们把它分解:

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:


  • 所有的网络配置文件现在是DependentOn中的web.config

  • 每个开发人员或团队需要自己的[用户/组] .Debug.config

  • 如果我们
  • 配置文件应该考虑转变发布,在释放模式或没有。

下面是它是如何做的:


  1. 右键单击Web项目,要做到这一点并选择卸载项目(而不是删除项目)。

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

再次右键单击同一Web项目(应显示为灰色现在),然后选择编辑......的csproj。这将打开XML编辑器项目。

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.config上市的部分。现在,注释掉的xml所有的DependentUpon的元素。

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

关闭XML编辑器并保存更改。接下来,你的项目再次右键单击,然后选择刷新。当项目重新加载,你会注意到Web.configs不再堆栈下的web.config。这是必要的,以帽子戏法TFS。

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.

现在,复制的web.config文件,将其粘贴在同一个项目并将其重命名为Web.base.config。这将被用于重新生成的Web.config每次(覆盖下)

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.config文件并进入文件 - >源代码控制 - >从源代码控制排除的Web.config。此外,打开源代码管理资源管理器(TFS Explorer视图),并找到在您的Web.config是位置和TFS删除。这样做是因为在Web.config将得到每次生成项目(我将在下盖)时重新生成。

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).

现在,我们要创建一个新的build文件,这将有助于我们重新生成的Web.config任何内置类型,即使是那些调试(这是转化的Web.config缺乏与开始)。在项目中创建一个新的XML文件并将其重命名为[命名为yourprojectname] .wpp.targets。它来命名这正是你的项目被称为包括所有的点,划等是很重要的(例如My.Project.wpp.targets)。

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).

现在,输入以下XML转换成新的文件。如果它开始强调语法错误,不要担心:

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

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="TransformXml"
               AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

    <!-- Make sure web.config will be there even for package/publish -->
    <Target Name="CopyWebConfig" BeforeTargets="Build;Rebuild">
        <Copy SourceFiles="Web.base.config"
              DestinationFiles="Web.config"
              OverwriteReadOnlyFiles="true"
              SkipUnchangedFiles="false" />
    </Target>

    <Target Name="CustomTarget" BeforeTargets="BeforeBuild">
        <Message Text="Transforming: Web.$(Configuration).config" Importance="high" />
        <TransformXml Source="Web.base.config"
                      Transform="Web.$(Configuration).config"
                      Destination="Web.config" />
    </Target>
</Project>


  • 现在,从你从来,从来编辑Web.config这一点上,它会被覆盖每一个应用程序编译时间。您只需编辑Web.base.config。

  • 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".

    现在,让我们的项目看起来就像是。再次右键单击该项目和卸载它。现在,再次右键单击和编辑吧。现在,回去取消注释所有我们在步骤#3注释掉的元素。此外,你应该添加Web.base.config元素下的DependentOn元素,这样它会显示下的web.config为好。关闭并保存它,然后再重新加载您的项目。你应该注意到,所有的configs现在下的web.config了。

    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.

    在这一点上,你可以,只要你想尽可能多的配置添加到您的项目/解决方案。例如,我添加了一个构建配置名为蒂姆(调试),但该项目的配置被称为Tim.Debug。当我右键单击Web.config文件,然后选择添加配置变换,它现在增加了我的Web.Tim.Debug.config文件。你也可以添加每个环境或每队CONFIGS。

    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.

    这是值得注意的是您的个性化配置文件只是一个子集Web.base.config,并在任何构建过程中,他们将被转化。要切换其转换会在调试过程中要建,就到你的解决方案的顶部,并选择你想要的构建配置。只要你有那个构建配置一个web.config,这将改变。如果没有,你会得到Web.base.config代替。


    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.

    请注意:这也应该使用标准的Windows / WPF的工作应用使用的app.config,以及代替

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

    这篇关于管理在VS2010和放大器团队web.config中; TFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆