I need to use different database connection strings and SMTP server addresses in my ASP.NET application, depending on where it is run, in development or production environment.
The application reads settings from Web.config file via WebConfigurationManager.AppSettings property.
I use Build/Publish command to deploy the application to production server via FTP and then manually replace remote Web.config with correct one.
Is it possible to somehow simplify the process of deployment? Thanks!
In Visual Studio 2010 and above, you now have the ability to apply a transformation to your web.config depending on the build configuration.
When creating a web.config, you can expand the file in the solution explorer, and you will see two files:
They contain transformation code that can be used to
See Web.config Transformation Syntax for Web Application Project Deployment on MSDN for more information.
It is also possible, albeit officially unsupported, to apply the same kind of transformation to an non web application app.config
file. See Phil Bolduc blog concerning how to modify your project file to add a new task to msbuild.
This is a long withstanding request on the Visual Studio Uservoice.
An extension for Visual Studio 2010 and above, "SlowCheetah," is available to take care of creating transform for any config file. Starting with Visual Studio 2017.3, SlowCheetah has been integrated into the IDE and the code base is being managed by Microsoft. This new version also support JSON transformation.