MSDeploy all configuration [.config files] in one package

不想你离开。 提交于 2019-11-30 14:56:46

You can achieve it using below solution. In between, I got the guidance from ONE OF THE BEST BOOK I HAVE READ IN LONG LONG TIME. Book is "Inside the Microsoft Build Engine" written by Sayed Ibrahim Hashimi and William Bartholomew. Book goes through the detail in excellent way.

Create a msbuild proj file as shown below

<?xml version="1.0" encoding="utf-8"?>

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="TransformAll">

  <UsingTask TaskName="TransformXml"  AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

  <PropertyGroup>
    <DestDirectory>C:\Temp\DeployPackage\TRANSFORM_CONFIGS\</DestDirectory>
  </PropertyGroup>

  <ItemGroup>
    <TransformFiles Include="$(FilesToTransform)"/>
  </ItemGroup>

  <Target Name="TransformAll" DependsOnTargets="ValidateSettings">
    <MakeDir Directories="$(DestDirectory)"/>
    <TransformXml Source="..\web.config"
                  Transform="%(TransformFiles.Identity)"
                  Destination="@(TransformFiles->'$(DestDirectory)%(Filename).transformed.config')" />
  </Target>

  <Target Name="ValidateSettings">
    <Error Text="FilesToTransform cannot be empty"
           Condition=" '$(FilesToTransform)'=='' "/>
    <Error Text="Couldn't find transform file at [%(TransformFiles.Fullpath)]"
           Condition =" !Exists('%(TransformFiles.Fullpath)') "/>
  </Target>

</Project>

After adding the above proj file and adding your environment specific files in a folder, simply run the below through msbuild accessible command line

msbuild transform.proj /t:TransformAll /p:FilesToTransform="Lab.config;Test.config;Live.config"

Hope this helps. Don't forget to buy/refer "Inside teh Microsoft Build Engine" book.

One possibility would be to customize the installer so the first dialog it displays lets the user choose the environment they are installing to. Based on that decision, the appropriate file would be copied to the install directory and renamed.

I am not 100% sure what you are looking for.

Do you want to have a root config file, that is updated from a "master" file containing all the environment specific settings? You should take a look at XmlPreProcessor http://xmlpreprocess.sourceforge.net/

In addition to Pedro's comment, you could also put a registry key on all your servers, stating what environment, the server belongs to. If you do a fully scripted deployment, the package will pick up the environment from that registry key, and produce the correct configuration for that environment. Saves the human step of choosing environment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!