调试代码时不转换web.config [英] Web.config is not transformed when debugging code

查看:25
本文介绍了调试代码时不转换web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要的 Web.config 文件,在它下面有一个 Web.Test.config, Web.Development.Config

I have a main Web.config file, and under that there is a Web.Test.config, Web.Development.Config etc.

当我在测试配置上通过 SlowCheetah 预览转换时,它似乎正确转换了值.

When I preview the transformation via SlowCheetah on the Test config, it appears to transform the values correctly.

当我将构建环境从开发切换到测试并尝试调试应用程序时,应用程序在主 Web.config 文件中的任何值下运行(即它不转换任何内容).

When I switch my build environment from Development to Testing and try to debug the application, the application runs under whatever values are in the main Web.config file (i.e. it is not transforming anything).

如何让构建环境在调试时选择正确的配置,而不是总是使用基本的 Web.config 文件?这可能吗?

How do I make the build environment pick the correct config when debugging rather than just always using the base Web.config file? Is this possible?

推荐答案

您可以在构建时转换 Web.config.将此目标添加到 *.csproj 文件:

You can transform Web.config on build. Add this target to *.csproj file:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild">
    <TransformXml 
        Source="Web.Base.config" 
        Transform="Web.$(Configuration).config" 
        Destination="Web.config" />
</Target>

Web.Base.config 中保留原始配置.启用转换就足够了,它适用于任何 XML 配置文件.不再需要SlowCheetah.

Keep the origin configuration in Web.Base.config. It's enough to enable transformation and it works for any XML config file. SlowCheetah is no longer needed at all.

http://sebnilsson.com/a5410281/asp-net-transform-web-config-with-debug-release-on-build/

这篇关于调试代码时不转换web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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