web.config transform at deploy time not build
Asked Answered
D

1

19

I'm wanting to know how to perform the following

  • Build & package an ASP.NET website to the file system
  • Be able to deploy the website to one or more environments. I want to the transforms of config file to happen at the point of deployment, rather than at the point of building. This way my code is not recompiled for each deployment and there is not risk of new changes being introduced.

From my own reading I'm unsure of how to do this. WebDeploy seems to package, transform and deploy based on a configuration but Im unsure how these steps can be decoupled to avoid the need to recompile code from source control.

Does anyone have any experience in solving this issue?

Dedie answered 3/5, 2013 at 7:11 Comment(2)
Have you seen the PackageWeb NuGet package? sedodream.com/2011/12/24/PackageOncePublishAnywhere.aspx nuget.org/packages/PackageWebBravo
OctopusDeploy ended up being the bigger picture solution to the problem I was trying to solve here.Dedie
H
11

You can use the Parameterization feature of web deploy a.k.a MSDeploy. You will need to use a parameters.xml file and a setParameters.xml file to dynamically swap out settings since you are not transforming your package at build time.

At deployment time you can pass in any .xml file to set the parameters you have specified in the parameters.xml file. Since the parameters.xml is at the root of your project solution (e.g see example link of where to place the file) then at build time it gets baked into your web package. However, you now have the flexibility to change those values by passing in the setParms .xml file from the command line during deployment. This is different than transforming the values during build time based on configuration settings.

Here is a msdeploy command line example of passing in a ParamFile for a staging environment.

msdeploy -verb:sync -source:package="c:\packages\mypackage.zip" -dest:auto,computername=StagingServer1 -setParamFile="c:\StagingParameters.xml"

See the below links for examples and MSDN technical information:

Web Deploy Parameterization in Action

Parameterization vs. Web.Config Transformation

Web Deploy Operation Settings

Similar question on stackoverflow that provides several methods

Honea answered 3/5, 2013 at 8:42 Comment(7)
Thanks @SoftwareCarpenter, the Parameterization feature has real potential. Do you know if it's possible to output multiple setParameters.xml files? ie: one for each environment. At this stage I'm missing how I can publish a set of params per environment so that one can later be chosen at deploy time.Dedie
Absolutely, that is the beauty of this approach. You can pass in any .xml file with the values for the environment you are targeting at deploy time using the setParamFile command line parameter. See updated answer for clarification and check the link "Web Deploy Parameterization in action" as well. Hope this helps.Honea
also check out this link if you still need more explanation: asp.net/web-forms/tutorials/deployment/…Honea
Does anything similar exist for app.config files in Windows services?Weizmann
Check out the SlowCheetah - XML Transforms visual studio extension.This package enables you to transform your app.config or any other XML file based on the build configuration. It also adds additional tooling to help you create XML transforms.. Written by: Sayed Ibrahim Hashimi, Chuck England and Bill Hiebert visualstudiogallery.msdn.microsoft.com/…Honea
can deploy.cmd do this?Scalenus
Yes, it is an option. Depends on approach if you want automated package for multi environments to build once deploy many then using deploy.cmd would require multi .zip packages built at build time as opposed to one package with just multi environment parameters files. A lot less space and can be easily trackable imo.Honea

© 2022 - 2024 — McMap. All rights reserved.