使用Visual Studio的web.config变换进行调试 [英] Use Visual Studio web.config transform for debugging

查看:230
本文介绍了使用Visual Studio的web.config变换进行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/3305096/how-can-i-use-web-debug-config-in-the-built-in-visual-studio-debugger-server\">How我可以使用Web.debug.config在内置Visual Studio调试服务器?

我想使用的web.config改造工作正常进行也发布了调试。

I want to use the web.config transformation that works fine for publish also for debugging.

当我发布一个Web应用程序时,Visual Studio自动将基于我currenc构建配置web.config中。
我怎么能告诉视觉工作室,当我开始调试做同样的。
在调试开始它只是使用均无需转换默认的web.config。

When i publish a web app, visual studio automatically transforms the web.config based on my currenc build configuration. How can i tell visual studio to do the same when i start debugging. On debug start it simply uses the default web.config without transformation.

任何想法?

推荐答案

确定,以理解 web.debug.config &安培; web.release.config 是包/只发布。我想出了在其中启用你正在尝试做的一种方式。我在<一个博客上讲述它href=\"http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx\">http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx.
下面是总结。

OK, with the understanding that web.debug.config & web.release.config are for package/publish only. I have come up with a way in which to enable what you are trying to do. I've blogged about it at http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx. Here is the summary.

现在让我们看看我们如何能够使这个问题提问者想要做什么。

Now let’s see how we can enable what the question asker wants to do.

要回顾一下,他建立在一个特定的配置,当他想要的特定变换被应用到的web.config 。所以,很显然你不希望保持一个的web.config 文件,因为它会被覆盖。

To recap, when he builds on a particular configuration he wants a specific transform to be applied to web.config. So obviously you do not want to maintain a web.config file, because it is going to be overwritten.

所以我们需要做的就是创建一个新的文件 web.template.config ,这仅仅是一个的web.config中<副本/ code>。然后,只需通过使用Windows资源管理器(使用Visual Studio,因为我们不希望从项目中删除它不删除)删除的web.config

So what we need to do is to create a new file web.template.config, which is just a copy of web.config. Then just delete web.config by using Windows Explorer (don’t delete using Visual Studio because we do not want to delete it from the project).

注意:如果您使用的是集成到Visual Studio,那么你可能想删除源代码控制的web.config一个源代码控制

还与这一点,我们不希望使用 web.debug.config web.release.config ,因为这些已经在Web发布管线一个定义良好的作用,所以我们不想打扰这一点。因此,而不是我们将创建两个新的文件,在同一文件夹,项目和 web.template.config web.dev.debug.config web.dev.release.config

Also with this we do not want to use web.debug.config or web.release.config because these already have a well defined role in the Web Publishing Pipeline so we do not want to disturb that. So instead we will create two new files, in the same folder as the project and web.template.config, web.dev.debug.config and web.dev.release.config.

我们的想法是,这些将是转换应用,当你调试或运行,从Visual Studio应用程序。现在,我们需要挂接到构建/包/发布过程中得到这一切接线。随着Web应用程序项目(WAP)还有就是你可以创建一个在同一个文件夹中的项目文件名为 {}项目名.wpp.targets ,其中<$ C的扩展点$ C> {项目名} 是项目的名称。如果此文件在磁盘上的同一文件夹中,然后WAP它会自动导入到项目文件。所以我创造了这个文件。而且我已经把下面的内容:

The idea is that these will be the transforms applied when you debug, or run, your application from Visual Studio. Now we need to hook into the build/package/publish process to get this all wired up. With Web Application Projects (WAP) there is an extensibility point that you can create a project file in the same folder with the name {ProjectName}.wpp.targets where {ProjectName} is the name of the project. If this file is on disk in the same folder as the WAP then it will automatically be imported into the project file. So I have created this file. And I have placed the following content:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Make sure web.config will be there even for package/publish -->
  <Target Name="CopyWebTemplateConfig" BeforeTargets="Build">
    <Copy SourceFiles="web.template.config"
          DestinationFiles="web.config"/>
  </Target>

  <PropertyGroup>
    <PrepareForRunDependsOn>
      $(PrepareForRunDependsOn);
      UpdateWebConfigBeforeRun;
    </PrepareForRunDependsOn>
  </PropertyGroup>

  <!-- This target will run right before you run your app in Visual Studio -->
  <Target Name="UpdateWebConfigBeforeRun">
    <Message Text="Configuration: $(Configuration): web.dev.$(Configuration).config"/>
    <TransformXml Source="web.template.config"
              Transform="web.dev.$(Configuration).config"
              Destination="web.config" />
  </Target>

  <!-- Exclude the config template files from the created package -->
  <Target Name="ExcludeCustomConfigTransformFiles" BeforeTargets="ExcludeFilesFromPackage">
    <ItemGroup>
      <ExcludeFromPackageFiles Include="web.template.config;web.dev.*.config"/>
    </ItemGroup>
    <Message Text="ExcludeFromPackageFiles: @(ExcludeFromPackageFiles)" Importance="high"/>
  </Target>
</Project>

让我来解释一下这一点。我创建了CopyWebTemplateConfig目标将始终复制 web.template.config 即使web.config中上打造,你是不是在Visual Studio中调试应用程序。

Let me explain this a bit. I have created the CopyWebTemplateConfig target which will always copy web.template.config to web.config on build, even if you are not debugging your application in Visual Studio.

这是必要的,因为我们仍然需要支持包/发布的Visual Studio的过程。然后我扩展属性 prepareForRunDependsOn 包含 UpdateWebConfigBeforeRun 目标。此属性用于确定哪些需要任何管理项目从Visual Studio中运行之前要执行的目标清单。

This is needed because we still need to support the package/publish process of Visual Studio. Then I extended the property PrepareForRunDependsOn to include the UpdateWebConfigBeforeRun target. This property is used to identify the list of targets which needs to be executed before any managed project is run from Visual Studio.

在这个目标我使用的是的TransformXML 任务转变 web.template.config ,使用正确的 web.dev。***。配置文件。这之后你的应用程序使用了正确的启动的web.config 根据您的生成配置。
从那以后,我有另一个目标 ExcludeCustomConfigTransformsFiles ,我注入到包/通过属性 BeforeTargets =ExcludeFilesFromPackage发布过程。这是必要的,因为我们不希望应用程序被打包或发布时,包括这些文件。
所以这真的是所有有给它。

In this target I am using the TransformXml task to transform web.template.config, using the correct web.dev.***.config file. After that your app starts up using the correct web.config based on your build configuration. After that I have another target ExcludeCustomConfigTransformsFiles, which I inject into the package/publish process via the attribute BeforeTargets="ExcludeFilesFromPackage". This is needed because we do not want these files to be included when the application is packaged or published. So that is really all there is to it.

要解释包/发布过程有点多为这种情况。当您打包/发布 web.debug.config web.release.config ,取决于构建配置,仍然会使用。但最终,它正在改变该文件是 web.template.config ,所以你可能取决于你在那个文件该怎么调整。问题/评论?

To explain the package/publish process a bit more for this scenario. When you package/publish web.debug.config or web.release.config, depending on build configuration, will still be used. But ultimately the file that it is transforming is web.template.config, so you may have to adjust depending on what you have in that file. Questions/Comments?

这篇关于使用Visual Studio的web.config变换进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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