I'm trying to find a way to transform my index.cshtml file when building my project.
For instance make this:
Ok, this will work.
Add an appsetting for it:
<add key="Environment" value="dev"/>
Then in your view add this:
In your other environments simply use transforms to replace it i.e.
<appSettings> <add key="Environment" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" /> </appSettings>
An alternative and I feel a better approach would be to abstract out the
WebConfiguration manager as an interface and have the app setting set in a model instead.
If it is in a common layout and set everytime maybe create a base model and have it set in an
OnActionExecuted in a base controller instead.