Web.config is not transformed when debugging code

You can transform Web.config on build. Add this target to *.csproj file:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild">
    <TransformXml 
        Source="Web.Base.config" 
        Transform="Web.$(Configuration).config" 
        Destination="Web.config" />
</Target>

Keep the origin configuration in Web.Base.config. It’s enough to enable transformation and it works for any XML config file. SlowCheetah is no longer needed at all.

To avoid unwanted transform on publish, use this (and check the comments and the link below for more details):

From a reminder in the comments I realized that I also have a
problem with Visual Studio transforming the XML twice, when Publishing
a project. The solution to this is to add a Condition to the
Target-tag like this:

<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">

http://sebnilsson.com/a5410281/asp-net-transform-web-config-with-debug-release-on-build/

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)