0

I am working on an ASP.NET C# project, where I would like to make use of web.config transforms.

I therefor installed the extension "Configuration Transform" and added a Web.Debug.config and Web.Release.config.

Within the Web.config I have not declared anything specific to my application. The debug config contains my testing/developing settings while the release config contains tokens #{someVar}# that later will get replaced by TFS.

When I publish my application the Web.config gets correctly created according to the configuration (debug/release). Also Preview config transform gives the correct result (besides the line breaks).

However when starting the application from within Visual Studio 2017 with debug configuration it complains about missing tags.

Why is that and how can I fix this?

Web.config

<!-- Does not contain the request tag -->

Web.Debug.Config

<request xdt:Transform="Insert">
    <mysetting>MyDevelopmentSetting</mysetting>
</request>

Web.Release.config

<request xdt:Transform="Insert">
    <mysetting>#{MyTokenThatWillGetReplacedByTFS}#</mysetting>
</request>
Matthias Güntert
  • 4,013
  • 6
  • 41
  • 89

1 Answers1

1

Web config transforms do not run in Visual Studio (when you press F5/run the app in VS). They only run on builds when publishing.

Since your web.config doesn't have the setting and the application is expecting it, it's properly complaining about the missing tag.

You will need to add this tag to your web.config.

Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
  • Thanks for replying. I guess that this will make my `web.debug.config` obsolete as my debug/development settings will have to move up into the `web.config` – Matthias Güntert Nov 21 '18 at 15:46
  • 1
    If you have a deployment to a dev server then debug might still make sense. The settings in your web.config could be to your local machine stuff. For example, a connection string to a local db. However, if you don't have that, then yes, your web.config could be your "dev/debug" settings and then you only have a release transform for production. :-) – Kevin LaBranche Nov 21 '18 at 15:49
  • Now... with that said. It is technically possible to get transforms to work on builds period but it creates more complexity and has downsides to it as well so if you really needed it, there are ways. I didn't offer any of them as your question was pretty straight forward with "Why isn't my transform running while debugging in VS". :-) – Kevin LaBranche Nov 21 '18 at 15:51
  • Have a look at this and the blog post in one of the answers.... https://stackoverflow.com/questions/35559289/web-config-is-not-transformed-when-debugging-code – Kevin LaBranche Nov 21 '18 at 15:56
  • Another... https://stackoverflow.com/questions/3613714/make-web-config-transformations-work-locally – Kevin LaBranche Nov 21 '18 at 15:57
  • I also have a setup but it's for a different purpose. I want to keep my web.config clean of secrets and out of source control. So, I have a config folder with appsettings.config.debug/release/whatever and connectionstrings.config.debug/release/whatever and use a prebuild step to move these files into my project on build so that I can have as many configurations as I want and not have them in source control and it works in VS. – Kevin LaBranche Nov 21 '18 at 15:59
  • It's based on this post https://weblog.west-wind.com/posts/2013/Feb/27/Sql-Connection-Strings-in-Config-Files-vs-Source-Control (external config section) – Kevin LaBranche Nov 21 '18 at 16:07