4

我正在使用 web.config 转换将条目插入 web.config 以用于某些构建配置。

例如我的 Web.Test.config 有这个条目:

<elmah>
    <errorMail from="me@me.com" to="me@me.com" async="false" smtpPort="25" smtpServer="mail" subject="test.senegal.co.uk Exception" xdt:Transform="Insert" />
</elmah>

这在视觉工作室中构建得非常好。

但是,当使用 msbuild 创建部署包时,该条目会在 web.config 中重复。这显然会导致异常。

有任何想法吗?

更新

我的“主”配置是 Web.Master.config而不是Web.config。web.config 文件在 Visual Studio 中构建时被覆盖。我想这一定与此有关。

我认为正在发生的是 msbuild 正在转换 web.config 而不是使用 Web.Master.config。

问题是如何告诉它使用正确的主人。

4

2 回答 2

4

我添加/p:TransformWebConfigEnabled=false了 msbuild 参数,因为我的 web.config 已经在 BeforeBuild 目标中进行了转换,如下所示:

<Target Name="BeforeBuild">
   <TransformXml Source="$(MSBuildProjectDirectory)\Web.Master.config" Transform="$(MSBuildProjectDirectory)\Web.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\Web.config" />
</Target>
于 2012-09-25T13:07:13.910 回答
3

在我的情况下,重复是由xdt:Transform="Insert". 如果将其从 Web..config 中删除并保留其余部分,它将正常工作,例如:

<!-- doesn't work -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="My" 
     xdt:Transform="Insert" />

对比

<!-- works -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="My" 
     />
于 2014-09-30T06:19:02.040 回答