ASP.NET and web.config transforms not working when developing

3.4k Views Asked by At

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>
1

There are 1 best solutions below

7
On BEST ANSWER

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.