Release Management for Visual Studio - Remove Web.Config Key

331 views Asked by At

What's the recommended way of removing a key from web.config during the build process for Release Management for Visual Studio 2013?

Using web.config transform, or adding a token for the entire line in the web.config (rather than using token for a value)?

Web.config Transform:

  <connectionStrings>
    <add name="myConnectionString" connectionString=""
      xdt:Transform="Remove" xdt:Locator="Match(name)"/>
  </connectionStrings>

Token Replacement:

__myConnectionString__
2

There are 2 answers

0
MrHinsh - Martin Hinshelwood On BEST ANSWER

You should use a transform for things that you want to happen at build time. Like removing any bits that you only use in development.

I usually have hard coded local values and then replace them with the release management keys during the transform. Then RM can own the rest.

1
Graham Smith On

I'm not sure about the recommended way but my recommended way of altering Web.config during build is to use a Web.config transform. So, in Web.Release.config (don't forget that if you are doing continuous delivery properly your build could go all the way to live so you need to be building as release) you might have something like this for a connection string:

<connectionStrings>
<add name="My ConnectionString"
     connectionString="Data Source=__DATA_SOURCE__;Initial Catalog=__INITIAL_CATALOG__;Integrated Security=SSPI;"providerName="System.Data.SqlClient"
     xdt:Transform="SetAttributes"xdt:Locator="Match(name)"/>
</connectionStrings>

This results in a tokenised version of the connection string in Web.config after the build so if you want something different eg to completely remove they key obviously use the Remove transform. You can see this in a bit more context in my blog post here. Note that I'm using transforms in conjunction with the /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false MSBuild argument.