Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing web.config transforms and Parameters.xml, or something to that effect

I've been using web.config transforms for a while now, for deployment on a few of our projects. What I'm now trying to achieve, is to have Web Deploy's 'Import Package' screen to prompt to check & update several of the variables in , adjusted for each environment.

I know I can use Parameters.xml to introduce these editable variables, but I haven't yet found how to have the defaults updated for different environment targets.

Consider the following neat, but non-overlapping example of wanting to have the user edit the 'specialServer' AppSetting, and have it present a different default when compiled for the NewEnv target:

Sample entry in Parameters.xml:

<parameter name="Special server" description="" tags="" defaultValue="server1-dev.domain">
    <parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='specialServer']/@value" />
</parameter>

Sample transform for Web.NewEnv.config, setting a different value for

<appSettings>
    <add key="specialServer"
        value="other-server.domain2"
        xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>

Sample of the prompt in Web Deploy:

enter image description here

Any suggestions as to how to update the default value for different build targets?

Thanks.

like image 530
Overflew Avatar asked Jul 25 '12 07:07

Overflew


People also ask

How does web config transform work?

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 add config transform?

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).


2 Answers

You would have to generate and new parameters definition file and embed it in your WebDeploy package for each environment.

This would give you different deploy packages per environment and would allow you to specify different default values for those parameters. Obviously doing so undermines the point if parameter transforms and you essentially end up baking in your config, but it's the only way to achieve what you want.

I don't recommend the approach but it may fit your needs.

like image 148
TheCodeKing Avatar answered Nov 14 '22 09:11

TheCodeKing


We use a batch script to call msdeploy. It allows for a parm to specify the Parameters.xml file. Then with multiple Parameters.xml files (one per environment), you can just call msdeploy like:

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='D:\mysite.zip' -dest:auto,computerName="testcomp1",includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"D:\mysite.test.SetParameters.xml"

like image 28
Ken H Avatar answered Nov 14 '22 07:11

Ken H