Webdeploy connectionstrings to xTokenize

We have an asp.net webapplication (full framework) and deploy it using release manager. The bits are in an artifact that is created during build with the contents of the webdeploy zip and a powershell desired state configuration (dsc) script to install te webapplication. Somewhere in the powershell script we use the xTokenize DscResource to set the connectionstrings and other settings.

mage courtesy of Kittikun Atsawintarangkul / FreeDigitalPhotos.net

In our initial setup we used the token file approach that is the default. Microsoft provided us with an example: https://www.powershellgallery.com/packages/xReleaseManagement/1.0.0.0/Content/Examples%5CxTokenize_TokenFile.ps1

The steps during build and release are:

  1. build performs web.config transformation to remove the debug (and other things),
  2. build replaces the web.config connectionstring with webdeploy tokens,
  3. build adds the web.token.config file to the artifact,
  4. release copies the web.config to the wwwroot directory,
  5. xTokenize replaces the web.config with the web.token.config,
  6. xTokenize replaces the tokens in web.config with actual values

It worked, but we had to copy every change in web.config to web.token.config. This felt cumbersome and error prune.

There was another example without the need of a token file: https://www.powershellgallery.com/packages/xReleaseManagement/1.0.0.0/Content/Examples%5CxTokenize_NoTokenFile.ps1 This could be combined with the web.config transformation to eliminate the need for a web.token.config. No more double administration and less steps in the build/release.

  1. build performs web.config transformation to remove the debug (and other things) also replaces the connectionstrings with the __TOKENS__ ,
  2. release copies the web.config to the wwwroot directory,
  3. xTokenize replaces the tokens in web.config with actual values

To stop the build from replacing the connectionstrings we defined a publish profile. The publish profile creates a pubxml file with the same name as the profile. We added the following line to the pubxml to stop the transformation of connectionstrings:

<AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>

Remember to use the /p:PublishProfile=YOUR_PROFILE_NAME in the build, else the connectionstrings are transformed since it is the default behaviour.

Now our web.release.config contains some more lines that replace the connectionstrings with the __TOKENS__ (we think that is a good thing) and the web.token.config had been removed.

The results are the same working webapplication, but the way to get there is less crooked.

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

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 )

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.