I can't find an example of my question on the web and was wondering if anybody knew a solution. Basically, if on our web.config we point to another file, like so:
<configuration> <configSections /> <appSettings file="AppSettings.config"> </configuration>
then how do we apply transformations to that external file?
Basically, I want to create an AppSettings.config, AppSettings.Debug.config, AppSettings.Release.config and have a transformation run over it... Is this even possible?
Thanks in advance,
Sergio
If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).
config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.
config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release. If you want to transform other files you can do that too.
There are few workarounds:
Workaround 1
AppSettings.Debug.config
, AppSettings.Release.config
with full values (not with transform attributes)web.config
, using transformation, substitute with the appropriate file:web.debug.config
<appSettings file="AppSettings.debug.config" xdt:Transform="SetAttributes" xdt:Locator="Match(file)"/>
web.release.config
<appSettings file="AppSettings.release.config" xdt:Transform="SetAttributes" xdt:Locator="Match(file)"/>
Its less than ideal, kinda defeats the purpose of transforms but may be appropriate based on one's situation than using something like SlowCheetah.
Workaround 2
Use TransformXml
build task to transform your files during build as pointed here and here
There's a Visual Studio plugin project called Slow Cheetah that takes the idea of transformations and allows you to apply it to files other than web.config, I haven't used it but I think it'll do what you want to do. Scott Hanselman did a blog on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With