3
votes

In the past I've using web.config transforms when manually deploying code to set environment specific setting values and attributes. I am transitioning from environment specific manual builds to a single TFS 2015 Build deployed to multiple environments via Release Management. Environment specfic application settings values configured in the web.config are tokenized. This method essentially inserts tokens into setting values during the build process. When deployed the tokens are replaced with matching Release definition configuration values.

This method is insufficient setting attributes of non-settings however. Examples of these transforms include:

<httpCookies requireSSL="true" xdt:Transform="Insert" />
<compilation xdt:Transform="RemoveAttributes(debug)" />
<httpRuntime xdt:Transform="RemoveAttributes(executionTimeout,maxRequestLength,useFullyQualifiedRedirectUrl,minFreeThreads,minLocalRequestFreeThreads,appRequestQueueLimit,enableVersionHeader)"/>
<httpRuntime enableVersionHeader="false" maxRequestLength="12288" xdt:Transform="SetAttributes"/>
<customErrors mode="On" xdt:Transform="SetAttributes"/>

What is the best way to update these attributes during release?

2

2 Answers

6
votes

Both Web Deploy's parameters.xml method and transforms can be used with Release Management. Transforms would be triggered from Build and the process of replacing tokens created by a publish would be triggered by Release Management.

To trigger transforms during the build, you can do this one of two ways:

  1. Add the following MSBuild parameters to force the transformation to happen during the build

    /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false

  2. Create a publish profile using the MSDeploy Package option and then trigger the packaging in Build using the following MSBuild parameters:

    /p:DeployOnBuild=true /p:PublishProfile=[nameOfProfile]

Either of the above methods will cause normal Web.config XDT's to run. If you need other XML files to be transformed, you'll need to first install SlowCheetah.

Token Replace and Parameters

Now that you have a build artifact with XDT's run, you can use token replacement and the WinRM tasks from Release Management. These will take the Web Deploy package from the Build and execute the SetParameters command before deploying it. The trick is to take the SetParameters.xml file and run a token replace on it first, swapping out Release environment variables first.

2
votes

User Sumo gave a proper answer, but I want to record some comments related to what instead of how.

IMHO there are different categories of settings to consider, let's exemplify. The database connection string changes at each environment, while requiring SSL should be turned on for all testing and production environments. In this perspective, you should have settings applied as early as possible, traditionally at build time and called Debug/Release builds; and last-minute settings, environment dependent, up to runtime settings, like Feature toggles.

So in my view you can use a single tool or multiple tools, but it is important that you properly categorize your settings accordingly.