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)