Oct 17, 2010 12:34 AM|cmac3095|LINK
Not sure if you are still interested in a solution. I spent many hours chasing my tail on google, etc. on this. Anyway, the links that helped me the most were:
http://stackoverflow.com/questions/2905151/msbuild-script-and-vs2010-publish-apply-web-config-transform. These gave me the clue I needed.
I don't mess with MSBUILD that much but my solution was to add a custom target to the XXX.Web.csproj that did the transform and then add a custom "Post build" event to the XXX.Web.csproj that invoked MSBUILD (to perform the transform) and an XCOPY to copy
the transformed web.config over the original. One side effect is that, as we have TFS, it always contains the last web.config that was transformed which can be a bit usettling (you keep thinking one of your other developers has overwritten your settings -
which, in a sense, they have ;-)....but, of course, your settings are in the web.xxxxxx.config you use in the transform. Okay, enough explanation.
Here's what you do: Copy and paste this into you XXXX.Web.csproj just above the commented out "Target Name="BeforeBuild" element...
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<MakeDir Directories="obj\$(Configuration)" Condition="!Exists('obj\$(Configuration)')" />
<TransformXml Source="Web.Config" Transform="Web.$(Configuration).config" Destination="obj\$(Configuration)\Web.config" StackTrace="true" />
That's it. On the next build of your xxx.web.config, the post build will run the custom target and generate transformed web.config. The XCOPY will overwrite the existing.