Question

I am using web.config transformations to insert entries into the web.config for certain build configurations.

E.g. my Web.Test.config has this entry:

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

This works absolutely fine building from visual studio.

However when creating a deployment package using msbuild, the entry is duplicated in the web.config. This obviously causes an exception.

Any ideas?

UPDATE

My "master" config is Web.Master.config not Web.config. The web.config file gets overwritten on build in visual studio. I think it must have something to do with this.

What I think is happening is msbuild is transforming web.config rather than using the Web.Master.config.

The question is how to tell it to use the right master.

Was it helpful?

Solution

I added /p:TransformWebConfigEnabled=false to the msbuild parameters, as my web.config was already being transformed in a BeforeBuild target like so:

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

OTHER TIPS

In my case duplication was caused by xdt:Transform="Insert". If remove it from Web..config and leave the rest it will work properly, e.g.:

<!-- 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" 
     />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top