EDIT: Much more refined approach can be found on SO:
Use Visual Studio web.config transform for debugging
I had commented that I too would like this feature but hadn't found a way to do it yet. Then decided to have a quick google.
A discussion here has lead me to one possible solution provided by cmac3095:
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"
/> <Target Name="Transform">
<MakeDir Directories="obj\$(Configuration)"
Condition="!Exists('obj\$(Configuration)')"
/>
<TransformXml Source="Web.Config" Transform="Web.$(Configuration).config"
Destination="obj\$(Configuration)\Web.config"
StackTrace="true" /> </Target>
<Target Name="AfterBuild">
</Target>
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.