Ari
Ari

Reputation: 3127

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.

Upvotes: 2

Views: 898

Answers (2)

glautrou
glautrou

Reputation: 3198

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.

Upvotes: 3

user2584307
user2584307

Reputation: 78

Configuration transformation is only done when publishing. Your base configuration file should have your development settings. If you choose to use the default build configurations, normally the release transform file should contain your production environment settings and the debug transform file will contain your test environment settings.

Personally, I usually create a new build configuration for testing and for production and leave the debug and release transforms empty.

Upvotes: 1

Related Questions