Search code examples
c#iisweb-configweb-config-transform

How does web.config files works in C# works?


Let's say that in my main startup project I have web.config file with some setting:

<!-- ... -->
<appSettings>
    <add key="Setting" value="setMe!" />
</appSettings>
<!-- ... -->

This project has two configurations: Release and Debug. Each transforms this setting to its own value, for example web.Debug.config:

<!-- ... -->
<appSettings xdt:Transform="Replace">
    <add key="Setting" value="debugValue" />
</appSettings>
<!-- ... -->

When I compile it there is no transformed config file. I have only three files: web.config, web.Debug.config and web.Release.config.


Solution

  • You have to publish your project ("Publish Web Site" command) and your destination (IIS) will use the correct web.config file with your Release configuration.