0
votes

How to create a release pipeline for IIS Deployment with XML Transformation

I create a build pipeline in azure devops.I am planning to create a release pipeline which needs to deploy the build in 3 IIS Websites(DEV,QA,STAG) to on Premise Servers (iam not using Azure servers)

As per my research, i created 3 configs in the application with their environment specific values in each config When i use the IIS Deploy task,i have an option to select the xml transformation.How does the xml transformation works?

2

2 Answers

2
votes

Xml transformation takes effect only when the configuration file(web.config) and transform file(web.stage.config) are in the same folder within the specified package. For more information you can check this official site

The transform file is an XML file that specifies how the Web.config file should be changed when it is deployed. For its syntax you can check this(https://docs.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110))

So in your case, Firstly you should specify a configuration file (eg. Web.config) and three transform files, the transform file should be named after its environment configuration(eg. web.dev.config, web.qa.config, web.stag.config).

In the these three transform files, specify the elements and attributes that need to be transformed with XDT syntax(check above syntax link)(XML-Document-Transform).

Secondly: you should create three stages named dev, qa, stag respectively in your release pipeline. enter image description here

Thirdly: enable XML transformation of IIS Web App Deploy task for each stage. enter image description here

Hope you can find above helpful?

0
votes

Refer to these steps below:

Step 1: Create a Asp.net Web Application (Name:SalesDemo)

Step 2.1: Create Nested Configs (e.g. web.SalesDemoQA.config, web.SalesDemoStag.config,web.SalesDemoProd.config), Copy to Output Directory: Always)

Sept 2. 2 open your csproj file in a text editor and check the following

 <None Include="web.SalesDemoQA.config">
          <DependentUpon>web.config</DependentUpon>             
 </None>

change the above code to the below code

<Content Include="web.SalesDemoQA.config">         
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content >

Step 2.3 Sample code in web.SalesDemoQA.config

 <connectionStrings>
      <add name="SalesDemo"   connectionString="Data Source=ReleaseSQLServer;Initial Catalog=SalesDemoDBQA;Integrated Security=True" 
                xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
     </connectionStrings>

Step 3: Login to Azure DevOPS site

Step 4: Create Build Pipeline

Step 4.1: Select a Repsotiory

Step 4.2: Select a Template (Asp.net Template)

Sep 4.3 msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False /p:PackageLocation="$(build.artifactstagingdirectory)\\"' platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)'

Note: I added the following additional parameters in the msBuildArgs /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False

Step 4.4: Publish Build Artifacts

Step 5 Create a Release pipeline

Step 5.1:Create a Stage Name:(SalesDemoQA)

Step 5.2 :Create IIS Web App Manage Task

Step 5.3 :Create IIS Web App Deploy Task

Step 5.4 :Set the (Package or Folder: $(System.DefaultWorkingDirectory)/_SalesDemo/drop/SalesDemo.zip;

Step 5.5 :Check XML transformation option

Assuming that the web.SalesDemoQA.config file will be transformed to web.config file.

Note :The Stage Name matches with the config name(www.salesDemo.config)