【发布时间】:2015-03-06 00:45:17
【问题描述】:
我正在尝试设置 web.config 转换来修改一些值。我正在使用 Octopus Deploy 给出的这个例子:
http://docs.octopusdeploy.com/display/OD/Configuration+files
web.config 的超精简版:
<?xml version="1.0" ?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
</system.web>
</configuration>
变换:
<?xml version="1.0" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
输出:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
</system.web>
</configuration>
我正在使用这个工具来预览转换: https://webconfigtransformationtester.apphb.com/
如您所见,它什么也没做。我看过很多例子,但显然我遗漏了一些东西。任何帮助将不胜感激。
(我也试过这个,但没有运气):
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation debug="false" xdt:Transform="Replace">
</compilation >
</system.web>
</configuration>
【问题讨论】:
-
你确定输入xml的命名空间吗?如果将其从
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"更改为xmlns:xdt="http://schemas.microsoft.com/.NetConfiguration/v2.0",则debug属性将从输出中删除。 -
谢谢你,Matthias,就是这样……我查看了大约 10 种不同的资源,但没有人提到我必须这样做。如果您想这样提交,我会将其标记为答案。
-
真正令人沮丧的是,我使用 Visual Studio 自动生成转换文件。如果转换需要该部分,您会认为将其添加到原始 web.config 中会很聪明。
-
无需更改原始 web.config
-
是的,在示例中,这个
<xdt:Import assembly="AppHarbor.TransformTester" namespace="AppHarbor.TransformTester.Transforms"/>似乎在转换中丢失了,因为它在 web.config 的configuration中没有任何命名空间的情况下工作。