SlowCheetah不会在构建时转换web.config [英] SlowCheetah not transforming web.config on build

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

问题描述

我通过nuget安装了SlowCheetah软件包,并基于Build config为我的web.config添加了转换文件. 但是,在构建时,不会对web.config进行转换.我检查了我的项目文件,并确实看到了SlowCheetah PropertyGroup和Import元素的条目.我没有在项目文件中看到转换目标. 如果我添加一个app.config,则app.config文件的确会转换. 据我了解,安装SlowCheetah软件包应将web.config转换目标自动添加到该项目的MSBuild文件中.我可以手动添加它,但我认为SlowCheetah可以立即使用. 我错过了什么吗?请让我知道. 我的要求是,应根据构建配置对我的web.config文件进行转换,并且转换后的web.config文件应位于输出目录中. 谢谢,感谢所有帮助.

I installed the SlowCheetah package via nuget and added transform files for my web.config based on Build config. However, on building, the web.config does not get transformed. I checked my project file and did see entries for SlowCheetah PropertyGroup and Import elements. I dont see a target for transformation in the project file. If I add an app.config, the app.config file does get transformed. It is my understanding that installing the SlowCheetah package should automatically add the web.config transform target to the MSBuild file for the project. I can add it manually but I thought SlowCheetah does it out of the box. Am I missing something. Please do let me know. My requirement is that my web.config file should get transformed based on build configuration and the transformed web.config file should be located in the output directory. Thanks and appreciate all help.

推荐答案

仅当您使用发布功能部署项目时,Visual Studio才会进行转换.为此,当您执行构建时,您需要调整MSBuild脚本.完整的解决方案是此处.这里是要领:

Visual Studio is doing Transformation only when you deploy your project by using the publish functionality. To do it when you do the build you need to tweak your MSBuild script. The complete solution is here. Here the essentials:

项目中的文件除了创建文件之外,还创建一个名为Web.Base.config的文件. 现有的Web.Debug.config和Web.Release.config.该文件将是 等同于您以前的Web.config,因为它将是 转变.您将得到以下文件:

Files in project Create a file named Web.Base.config, besides the existing Web.Debug.config and Web.Release.config. This file will be the equivalent to your old Web.config, as it will be the base for the tranformation. You will end up with these files:

Web.config,Web.Base.config,Web.Debug.config,Web.Release.config和 Web.config.将以下配置添加到您的底部 .csproj文件,就在结束标记-

Web.config, Web.Base.config, Web.Debug.config, Web.Release.config, and Web.config. Add the following configuration to the bottom of your .csproj-file, just before the closing -tag:

<Target Name="BeforeBuild">
    <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>

更新:从评论的提醒中,我意识到我也有一个 发布时Visual Studio将XML转换两次的问题 一个专案.解决方案是在其中添加一个条件 像这样定位目标标签:

UPDATE: From a reminder in the comments I realized that I also have a problem with Visual Studio transforming the XML twice, when Publishing a project. The solution to this is to add a Condition to the Target-tag like this:

<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">

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

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