I have a c# website that I've been deploying through iis7/webdeploy and that works great. Problem is when I update the site the web.config file gets overwritten. This file contains there database connection and a few other settings specific to their site. Since release I've been updating their sites by logging in, copying the web.config, re-running the import, and re-coping the web.config back. I've screwed myself a couple of times by forgetting to do so which then causes a lot of extra work on my part. However, now I'm working on getting the web interface in as part of my automated deployment so I need to figure out why it's overwriting the current configuration of the site.
Does anyone know why the web.config is getting overwritten and/or how to fix it so it doesn't do that anymore?
Thanks! Scott
You have two options when using web deploy:
When using parameterization, you specify which settings can be modified during deployment of a package. For example, you can create parameters for your connection string, WCF config or app settings. When an administrator now deploys your application they can modify all settings for the current installation. This approach is useful when you are deploying one package to multiple environments. Using things like XmlPoke you can completely automate this process.
For a complete description of how to use parameters see: Reference for the Web Application Package.
Web.config transformation is done at compile time. By creating multiple configurations you can change values in your web.config file using XSLT. These changes are applied when you build the package. SlowCheetah is a great tool that will help you to test your transformations. By creating specific configurations (for example: staging, test, production) you can use these configurations in your deployment pipeline to configure all settings correctly.
For more information on how to use web.config transformations see: Web.config Transformation Syntax for Web Project Deployment Using Visual Studio
Parameterization gives you more freedom but is also more complex. Web.config transformations are easy to use and can be used when you know upfront the environments you are going to deploy to.
As of .NET Core, the simple answer is to leave web.config alone and specify the environment in your publish profile instead. That, in turn, sets web.config for you.
For Windows IIS deployments: Include the
<EnvironmentName>
property in the publish profile (.pubxml) or project file. This approach sets the environment in web.config when the project is published:<PropertyGroup> <EnvironmentName>Development</EnvironmentName> </PropertyGroup>
Source: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments
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