Search code examples
c#asp.net.netweb.config-transform

When the web.config file will be converted, and if there is a way to run it in Visual Studio to verify it


In ASP.NET, the value setting was set differently according to the release and debug of the web.config file.

So it doesn't apply to running to see if it's applied in Visual Studio. I wonder when the web.config file will be converted, and if there is a way to run it in Visual Studio to verify it.


Solution

  • The transforms (unfortunately) only occur when you use the publishing options.

    So, while you are allowed to have multiple configurations. (say, debug, Dev, Production), the transforms ONLY occur at publish time, and not say when you build local.

    In fact, even when you set the project to release, and build? You still are using the debug web.config, and the transforms do not occur.

    So, that is this option:

    enter image description here

    So, how to view what the transform will look like?

    Most simple is to create a file folder publish (to a local folder on your dev computer). You can publish say as release, and then in that folder, you can open and view the web.config file that now been transformed.

    I can't say there is any great way to "test" or "validate" that the new web config is ok other then of course trying to deploy.

    In place of a publish, you can also as a quick test during development or setting up the transforms, you can right click on the web.config, and choose "Preview".

    Hence this:

    enter image description here

    So, I have 3 configs. The main web.config (with most of the settings). Then I have dev, and then release.

    So, I use dev for a publish to the dev server. (for people internal to test the site along with QA people (quality assurance)).

    And then I have a release config used for the final real deploy to the production web server. Only my release version runs say https, the local and dev server only uses http (I don't have a signed security certificate setup local nor for the dev test server).

    As noted, it is somewhat unfortunate that the multiple configs and their transforms can't be used by selecting the build configuration. In fact, EVEN setting the configuration to release and building the project does NOT do any transforms, and will continue to use the default web.config.

    So, just keep in mind, you can right click and use "preview". And keep in mind that changing the build (debug, dev, release) does not transform the web.config file, but only using publishing will.