Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web.config is not transformed when debugging code

I have a main Web.config file, and under that there is a Web.Test.config, Web.Development.Config etc.

When I preview the transformation via SlowCheetah on the Test config, it appears to transform the values correctly.

When I switch my build environment from Development to Testing and try to debug the application, the application runs under whatever values are in the main Web.config file (i.e. it is not transforming anything).

How do I make the build environment pick the correct config when debugging rather than just always using the base Web.config file? Is this possible?

like image 824
mameesh Avatar asked Feb 22 '16 16:02

mameesh


People also ask

How do I enable transformation in Web config?

Release. config transformation files that are created by default for the two default build configurations. You can create transformation files for custom build configurations by right-clicking the Web. config file and choosing Add Config Transforms from the context menu.

How do I enable debugging in Web config?

In the Web. config file, locate the compilation element. Debugging is enabled when the debug attribute in the compilation element is set to true. Change the debug attribute to false to disable debugging for that application.

Where is Web config file in Visual Studio 2022?

config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder.


2 Answers

You can transform Web.config on build. Add this target to *.csproj file:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" /> <Target Name="BeforeBuild">     <TransformXml          Source="Web.Base.config"          Transform="Web.$(Configuration).config"          Destination="Web.config" /> </Target> 

Keep the origin configuration in Web.Base.config. It's enough to enable transformation and it works for any XML config file. SlowCheetah is no longer needed at all.

http://sebnilsson.com/a5410281/asp-net-transform-web-config-with-debug-release-on-build/

like image 124
Ilya Chumakov Avatar answered Sep 27 '22 21:09

Ilya Chumakov


XML transformations will only be applied when you publish web apps and not during build.

This blog post details a work around using build settings.

like image 33
Christopher Dunn Avatar answered Sep 27 '22 23:09

Christopher Dunn