I have the following key in my Web.config
file:
<appSettings>
<add key="ImageBucketName" value="dev" />
</appSettings>
I have the following transformation in my Web.Release.Config
file:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="ImageBucketName" value="live" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
However, when I run my application from Visual Studio 2013 and attempt to retrieve the value of the key from with my controller, I am always getting the non-transformed version of the key.
// Get the AWS bucket name from the config file
var imageBucketName = ConfigurationManager.AppSettings["ImageBucketName"];
The same result with the following:
// Get the AWS bucket name from the config file
var imageBucketName = WebConfigurationManager.AppSettings["ImageBucketName"];
How can I ensure that I'm getting the correct Release version of the key when I'm running the application as 'Release'?
Transforms won't be applied when running directly in Visual Studio - you would need to at least deploy somewhere (even if locally) first.
The rationale is something along the lines of transforms being applicable to different environments. The base web.config file represents the local (dev) environment, while the .release
transforms would be applicable for prod (or prod-like) environments.
If you just want to see the transforms in action, an easy way to run them is via the command-line XDT tool available from https://ctt.codeplex.com/
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments