How to prevent web.config getting overwritten using webdeploy on an update to a site
Asked Answered
S

4

10

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

Stilt answered 26/7, 2013 at 11:54 Comment(2)
Which settings are you using for webdeploy? Do you have a web.release.config file that contains the correct connection string?Parthenope
Can you not just set the "Build Action" of the Web.config (under properties) to "None"? I would imagine at the moment it is set to "Content" so it is copied to the server every time you publish.Ss
P
9

You have two options when using web deploy:

  • Parameterization
  • Web.config transformations

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.

Parthenope answered 26/7, 2013 at 12:19 Comment(0)
G
3

Changing the "Build Action" of the Web.config file to "None" worked for me. Bear in mind you'll have to change this if you're deploying to a new machine.

Gleeful answered 14/4, 2019 at 17:59 Comment(1)
Thanks a lot...Such a simple solution for this...We wasted 1 hour on this :)Erbil
B
2

Sounds like you need to configure your web.config transforms. Take a look here:

http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx

Broach answered 26/7, 2013 at 12:0 Comment(1)
This sounds promising. I'm going to try it. Thanks!Stilt
P
2

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://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments

Pay answered 12/11, 2020 at 4:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.