0

First of all I know there are several pages about this issue e.g. Web.Config Debug/Release, Web.config Transformation Syntax now generalized for any XML configuration file and Web.config File Transformations. But most of them are outdated and does not mentioned clearly about all of the three files: Web.config, Web.Debug.config, Web.Release.config.

So, assume that I have the following settings for Web.config:

Web.config:

<appSettings>
    <add key="ClientId" value="xxxxx"/>
    <add key="ClientSecret" value="xxxxx"/>
</appSettings>

And I want to use these settings in debug and release in the following ways:

Web.Debug.config:

<appSettings>
    <add key="ClientId" value="ddddd"/>
    <add key="ClientSecret" value="ddddd"/>
</appSettings>

Web.Release.config:

<appSettings>
    <add key="ClientId" value="rrrrr"/>
    <add key="ClientSecret" value="rrrrr"/>
</appSettings>

1) What is the procedures to perform this accurately? I think while debugging and publishing, these settings are used automatically according to my selection Debug or Release in Visual Studio run and publish dialog. Is that true?

2) Should I remove these settings from Web.config after moving to Web.Debug.config and Web.Release.config?

3) What is the Test selection in the Configuration field of the Publish dialog in VS?

Any help would be appreciated.

7
  • Does anybody else have no idea? Any help pls? Commented May 6, 2020 at 14:41
  • 1
    Is this for ASP.NET or ASP.NET Core? You've tagged both. Commented May 6, 2020 at 16:15
  • @ChrisPratt Hi Chris, sorry I forget the difference. It is ASP.NET MVC, I am waiting for your valuable answer and comments. Thanks in advance. Commented May 6, 2020 at 19:27
  • @ChrisPratt On the other hand, as far as I know we can use transformation in web.debug.config and web.debug.config both, or in one of them according to our needs. I mean that, assume we have a connection string for prod database in web.config and need to use connection string for test database while debugging. In that case we should define test connection string (with transformed form of course) web.debug.config and we do not anything in web.release.config. Is that true? Commented May 6, 2020 at 20:56
  • @ChrisPratt Alsı I realized that when debugging in VS, it uses only web.config configuration even if I select Release. But I expect to use web.release.config when selecting release. Is it normal? Commented May 6, 2020 at 23:19

1 Answer 1

0

I would recommend reading an overview of how web.config transforms work:

https://blog.elmah.io/web-config-transformations-the-definitive-syntax-guide/

In general, the Web.*.config files will make changes to the Web.config file depending on the selected publish configuration in Visual Studio. For example, if you want to update/replace a value in a debug publish, your Web.Debug.config file should look like:

<configuration xmlns:xdt="...">
  <appSettings>
    <add key"ClientId" value="ddddd" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
    <add key"ClientSecret" value="ddddd" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
  </appSettings>
</configuration>

Here is the current Microsoft documentation on how these work: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-3.1

Sign up to request clarification or add additional context in comments.

14 Comments

Thanks for reply, I read that article and it is updated. However, it uses a extension and does not mention three config files that I asked in my question. Instead, I am looking for an explanation easy step-by-step without extension. On the other hand, in that article it uses isProd, but many other articles don't use and only use key name.
On the other hand, as far as I know we can use transformation in web.debug.config and web.debug.config both, or in one of them according to our needs. I mean that, assume we have a connection string for prod database in web.config and need to use connection string for test database while debugging. In that case we should define test connection string (with transformed form of course) web.debug.config and we do not anything in web.release.config. Is that true?
Any help please?
I have only used web.config transforms for publishing to various environments as outlined in devblogs.microsoft.com/aspnet/…. I typically have the connection string(s) in the base web.config pointing to the development database(s), then transform(s) in web.release.config to replace the connection string(s) with the production value(s). When I need to debug against a database other than development, I temporarily change the values in the base web.config. Is that what you are trying to do? We have one transform per environment.
Your last comment is much more detailed and clarified me, thanks. In this scene, could you confirm the following issues pls? There are 3 web config as you know: base (web.config), debug (web.debug.config) and release (web.release.config). Assume that I have a dev and prod environment and 2 different connectionStrings for them. >>>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.