MSDeploy all configuration files [.config] in one package

At the moment, we have 4 different environments (Lab, Test, Stage, LIVE), and we have implemented automatic deployment using Nant / CC.Net. I study and do some research on what can be done more efficiently with the new MSDeploy tool.

What I want to achieve is to create a package with a configuration folder inside which we will have all the different configuration files for all possible environments (basically adding all the configuration conversion files)

What I want to achieve is automatic deployment in our corporate environment, where the development team does not have access to the server, where it will be deployed. We just need to pass the deployment package with a predefined instruction on how to install the package.

What is the best approach you can come up with. WE DO NOT USE TFS and do not want the automatic build process to depend on any process as such, except for MSDeploy or something that is easy to replace. Thinking of using MSBuild too.

+6
source share
3 answers

You can achieve this using the solution below. Between them, I received guidance from ONE OF THE BEST BOOK I READ IN LONG LONG TIME. Book Inside Microsoft Build Engine , written by Sayed Ibrahim Hashimi and William Bartholomew. The book looks through the details perfectly.

Create the msbuild project 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 to the folder, simply run the msbuild command line below.

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

Hope this helps. Do not forget to buy / link to the book "Inside the Microsoft Build Engine."

+8
source

One possibility would be to configure the installer so that the first dialog displayed allows the user to choose the environment in which they are installed. Based on this decision, the corresponding file will be copied to the installation directory and renamed.

0
source

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

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

In addition to the Pedro comment, you can also put the registry key on all your servers, indicating in which environment the server belongs. If you fully deploy the script, the package will pick up the environment from this registry key and create the correct configuration for this environment. Saves the human step of choosing the environment.

0
source

Source: https://habr.com/ru/post/890562/


All Articles