Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.config transform at deploy time not build

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?

like image 229
Dav Evans Avatar asked May 03 '13 07:05

Dav Evans


People also ask

How do I create a new transformation in Web config?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

What is Xdt transformation?

XDT is a simple and straight forward method of transforming the web. config during publishing/packaging. Transformation actions are specified using XML attributes defined in the XML-Document-Transform namespace, that is mapped to the xdt prefix.

What is Web config transform?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do you slow a cheetah?

Step 1: Install the package "Slow Cheetah" into your solution. Step 2: Right click on the App. config and select the option Add Transform. Step 3: To tweak the appsetting values ,connection strings etc based on the configuration environement.


1 Answers

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

like image 182
SoftwareCarpenter Avatar answered Sep 28 '22 03:09

SoftwareCarpenter