我正在使用web.config转换将条目插入到web.config中以用于某些构建配置。
E.g。我的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。
问题是如何告诉它使用正确的主人。
答案 0 :(得分:2)
我在msbuild参数中添加了/p:TransformWebConfigEnabled=false
,因为我的web.config已经在BeforeBuild目标中进行了转换,如下所示:
<Target Name="BeforeBuild">
<TransformXml Source="$(MSBuildProjectDirectory)\Web.Master.config" Transform="$(MSBuildProjectDirectory)\Web.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\Web.config" />
</Target>
答案 1 :(得分:2)
在我的情况下,重复是由xdt:Transform="Insert"
引起的。如果从Web..config中删除它并保留其余部分它将正常工作,例如:
<!-- doesn't work -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="My"
xdt:Transform="Insert" />
VS
<!-- works -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="My"
/>