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

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

问题描述

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

解决方案

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

<块引用>

项目中的文件 创建一个名为 Web.Base.config 的文件,除了现有的 Web.Debug.config 和 Web.Release.config.该文件将等同于您的旧 Web.config,因为它将是转型.你最终会得到这些文件:

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

<目标名称="BeforeBuild"><TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config"/></目标>

<块引用>

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

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

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 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:

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, 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>

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天全站免登陆