Search code examples
c#.netcontinuous-integrationcd

How to manage connectionstring for CD


I have a legacy .net application running 4.0 that I have been given to maintain and as part of the maintenance I am updating the CI/CD system.

In doing that I found a bunch of manual file content replaces used to manage environment specific variables.

One of these is the connection string, I was wondering what the recommended way of handling connection strings in app and web.config files is across environments.

I tried slowcheetah but it doesn't do the transform for the web.config when you are not using the publish option.

Thanks for any help.


Solution

  • Yes you can do this with a msbuild script:

    <UsingTask TaskName="TransformXml" AssemblyFile="bin\Microsoft.Web.Publishing.Tasks.dll"/>
    
    
      <Target Name="GenerateConfigs">
    
        <MakeDir Directories="$(BuildOutput)" Condition="!Exists('$(BuildOutput)')"/>
    
        <TransformXml Source="BTSNTSvc.exe.config"
    
                      Transform="BTSNTSvc.exe.$(Configuration).config"
    
                      Destination="$(BuildOutput)\BTSNTSvc.exe.config"/>
    
      </Target>
    

    Please review the following resources for performing a config transform without having to do a publish. This snippet was taken from the 2nd link.

    http://matthewvukomanovic.blogspot.com/2012/10/webconfig-transform-without-publishing.html

    http://geekswithblogs.net/EltonStoneman/archive/2010/08/20/using-msbuild-4.0-web.config-transformation-to-generate-any-config-file.aspx