Declaring optional MSDeploy parameters using the Web Publishing Pipeline

Today’s WPP vs MSDeploy issue is declaring parameters that need to be ignored at deployment time.

Why would I want to declare a parameter, only to ignore it? I’m a big fan of continuous delivery, and one of it’s tenants is to only create build artifacts once and deploy them to various environments (dev, uat, staging, live), as it guarantees that what you deploy is what you tested.

MSDeploy actually provides two (subtlely different) ways of skipping a parameter. The removeParam argument can be used to remove the parameter definition for the current deployment. Alternatively, the parameter can be decorated with a <parameterValidation kind="AllowEmpty" /> element to allow parameter values of empty strings.

Unfortunately, neither of these MSDeploy features are supported by the Web Publish Pipeline.

The only workaround for removeParam is to perform your deployments using MSDeploy directly, since there’s no way to specify custom command line arguments via the MSDeploy (or VsMsDeploy) tasks.

Fortunately, there is a workaround for the parameterValidation method, which ended up being what I needed. I found the workaround after snooping through Microsoft.Web.Publishing.targets (in %programfiles%\MSBuild\VisualStudio\v11.0\Web), a wealth of obfuscated knowledge on WPP features that are not-so-documented.

It turns out that WPP will actually load a Parameters.xml file (technically $(ProjectParametersXMLFile)) from the root of the web application and merge any parameters with those declared in WPP (including Project.wpp.targets) using MSDeployDeclareParameters. For example, the following Parameters.xml declares an optional text-replace parameter:

<parameters> 
   <parameter name="ReplaceVariable" 
              description="Sample variable that allows empty values" defaultValue="">
      <parameterValidation kind="AllowEmpty" />
      <parameterEntry type="TextFile" scope="Web\.config$" match="TextToReplace" /> 
    </parameter> 
</parameters> 

You can now deploy the application while specifying an empty parameter value for ReplaceVariable

External links:

About these ads
This entry was posted in Deployment and tagged , . Bookmark the permalink.

2 Responses to Declaring optional MSDeploy parameters using the Web Publishing Pipeline

  1. Richard, thanks a lot for your contributions. I really appreciate your willingness to share your knowledge.
    I’d love to interact with you directly going forward regarding web publishing. If you are interested please email me. I can provide you with info to help unblock you and would like to understand your biggest pain points.

  2. test website says:

    I don’t usually comment but I gotta state regards for the post on this great one .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s