Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we update the web.config file using WinRM - IIS Web App Deployment Task

Is there any way we can update the web.config file while deploying the application on local IIS Server using WinRM - IIS Web App Deployment task from Azure DevOps release Pipeline.

Below is the problem statement.

  • I have Asp.net Application present in source code management (AzureDevops Repositories)
  • I want to update the Web.config file for database connections, external 3rd party URL, etc

  • I want to perform the same operations using WinRM - IIS Web App Deployment Task

I know ideally this can be done using other tasks like Update Config task present in AzureDevops Marketplace.

First up all I want to check if this is feasible

Can we achieve it using Web Deploy Parameter File & Override Parameters Options which are available in the WinRM - IIS Web App Deployment Task.

ReleasePipeline

Logs from the Task is available below:

2019-07-24T14:08:09.5094037Z ##[debug]PowerShellHandler.Execute - AddParameter(WebDeployParamFile=E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml)
2019-07-24T14:08:09.5098039Z ##[debug]PowerShellHandler.Execute - AddParameter(OverRideParams=name="SampleWebAppDb-Web.config Connection String",value="new connectionstring"
2019-07-24T14:08:09.5100161Z name="TargetValueChange",value="Value is Changed")
2019-07-24T14:08:09.7289513Z ##[debug]Loading module from path 'E:\NewAgent\_work\_tasks\IISWebAppDeploy_50acc50f-7d15-470b-83c1-578b3f3eeba2\1.4.6\DeploymentSDK\InvokeRemoteDeployment.ps1'.
2019-07-24T14:08:09.7352020Z ##[debug]Dot-sourcing the script file 'E:\NewAgent\_work\_tasks\IISWebAppDeploy_50acc50f-7d15-470b-83c1-578b3f3eeba2\1.4.6\DeploymentSDK\InvokeRemoteDeployment.ps1'.
2019-07-24T14:08:09.7560871Z ##[debug]Entering script DeployIISWebApp.ps1
2019-07-24T14:08:09.7695237Z ##[debug]machinesList = localhost
2019-07-24T14:08:09.7696254Z ##[debug]adminUserName = desktop-0dnhide\hp
2019-07-24T14:08:09.7698716Z ##[debug]winrmProtocol  = Http
2019-07-24T14:08:09.7699874Z ##[debug]testCertificate = true
2019-07-24T14:08:09.7702175Z ##[debug]webDeployPackage = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip
2019-07-24T14:08:09.7702410Z ##[debug]webDeployParamFile = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml
2019-07-24T14:08:09.7703755Z ##[debug]overRideParams = name="SampleWebAppDb-Web.config Connection String",value="new connectionstring"
2019-07-24T14:08:09.7703971Z name="TargetValueChange",value="Value is Changed"
2019-07-24T14:08:09.7705526Z ##[debug]websiteName = MainApp/APP1
2019-07-24T14:08:09.7706521Z ##[debug]removeAdditionalFiles = false
2019-07-24T14:08:09.7708165Z ##[debug]excludeFilesFromAppData = false
2019-07-24T14:08:09.7708778Z ##[debug]takeAppOffline = false
2019-07-24T14:08:09.7710018Z ##[debug]additionalArguments = 
2019-07-24T14:08:09.7710541Z ##[debug]deployInParallel = true
2019-07-24T14:08:09.7761001Z ##[debug]Triming inputs for excess spaces, double quotes
2019-07-24T14:08:09.8269846Z ##[debug]Executing main function in MsDeployOnTargetMachines : Execute-Main -WebDeployPackage "E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip" -WebDeployParamFile "E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml" -OverRideParams "name=`"SampleWebAppDb-Web.config Connection String`",value=`"new connectionstring`"
2019-07-24T14:08:09.8270269Z name=`"TargetValueChange`",value=`"Value is Changed`"" -WebsiteName "MainApp/APP1" -RemoveAdditionalFiles false -ExcludeFilesFromAppData false -TakeAppOffline false -AdditionalArguments ""
2019-07-24T14:08:09.8566125Z Starting deployment of IIS Web Deploy Package : E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip
2019-07-24T14:08:09.8566522Z 
2019-07-24T14:08:09.8566618Z 
2019-07-24T14:08:09.8721777Z ##[debug]Entered Invoke-RemoteDeployment function
2019-07-24T14:08:09.8722346Z ##[debug]machinesList = localhost
2019-07-24T14:08:09.8723967Z ##[debug]adminUserName = desktop-0dnhide\hp
2019-07-24T14:08:09.8725568Z ##[debug]protocol = Http
2019-07-24T14:08:09.8769871Z ##[debug]Creating credentials object for connecting to remote host
2019-07-24T14:08:09.8918408Z ##[debug]Tokenizing machine name and port, to create dictonary
2019-07-24T14:08:09.9235805Z ##[debug]Splitting machine name and port into tokens
2019-07-24T14:08:10.0182997Z ##[debug]Using skipCA = True
2019-07-24T14:08:10.0194123Z ##[debug]Using useHttp = True
2019-07-24T14:08:10.0216648Z Performing deployment in parallel on all the machines.
2019-07-24T14:08:10.0217058Z 
2019-07-24T14:08:10.0217233Z 
2019-07-24T14:08:10.0309977Z Deployment started for machine: localhost with port 5985.
2019-07-24T14:08:10.0316467Z 
2019-07-24T14:08:10.0317179Z 
2019-07-24T14:08:10.2247380Z ##[debug]Exporting function 'New-PSWorkflowSession'.
2019-07-24T14:08:10.2250179Z ##[debug]Exporting alias 'nwsn'.
2019-07-24T14:08:30.8101839Z ##[debug]Processed: ##vso[task.setprogress value=-1;] 
2019-07-24T14:08:30.8185994Z Deployment status for machine localhost : Passed
2019-07-24T14:08:30.8186905Z 
2019-07-24T14:08:30.8187252Z 
2019-07-24T14:08:30.8221717Z 
2019-07-24T14:08:30.8223208Z     Deployment started on target machine...
2019-07-24T14:08:30.8223964Z 
2019-07-24T14:08:30.8225201Z Entering script MsDeployOnTargetMachines.ps1
2019-07-24T14:08:30.8226227Z 
2019-07-24T14:08:30.8226516Z Entering Execute-Main function
2019-07-24T14:08:30.8226760Z 
2019-07-24T14:08:30.8226994Z WebDeployPackage = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip
2019-07-24T14:08:30.8227565Z 
2019-07-24T14:08:30.8228092Z WebDeployParamFile = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml
2019-07-24T14:08:30.8228215Z 
2019-07-24T14:08:30.8228421Z OverRideParams = name="SampleWebAppDb-Web.config Connection String",value="new connectionstring"
2019-07-24T14:08:30.8228607Z name="TargetValueChange",value="Value is Changed"
2019-07-24T14:08:30.8232239Z 
2019-07-24T14:08:30.8232354Z ##[command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msDeploy.exe"  -verb:getParameters -source:package='E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip'
2019-07-24T14:08:30.8233350Z 
2019-07-24T14:08:30.8233526Z MsDeploy command line arguments:  -verb:sync -source:package="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip" -dest:auto -setParamFile="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml" -setParam:name="SampleWebAppDb-Web.config Connection String",value="new connectionstring" -setParam:name="TargetValueChange",value="Value is Changed" -setParam:name="IIS Web Application Name",value="MainApp/APP1" -enableRule:DoNotDeleteRule -retryAttempts:3 -retryInterval:3000
2019-07-24T14:08:30.8233600Z 
2019-07-24T14:08:30.8233781Z Deploying website. Running command: "C:\Program Files\IIS\Microsoft Web Deploy V3\msDeploy.exe"  -verb:sync -source:package="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip" -dest:auto -setParamFile="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml" -setParam:name="SampleWebAppDb-Web.config Connection String",value="new connectionstring" -setParam:name="TargetValueChange",value="Value is Changed" -setParam:name="IIS Web Application Name",value="MainApp/APP1" -enableRule:DoNotDeleteRule -retryAttempts:3 -retryInterval:3000
like image 670
E_FreeLancer Avatar asked Dec 06 '25 14:12

E_FreeLancer


1 Answers

You can override parameters value by specifying them in Override Parameters. For example:

Web.config:

<connectionStrings>
    <add name="DefaultConnection" connectionString="old string" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="email" value="[email protected]"/>
    <add key="url" value="example.com"/>
  </appSettings>

Parameters.xml:

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
  <parameter name="email" description="description"> 
    <parameterEntry kind="XmlFile"
                    scope="\\web.config$"
                    match="/configuration/appSettings/add[@key='email']/@value" />
  </parameter>
  <parameter name="url" description="description">
    <parameterEntry kind="XmlFile"
                    scope="\\web.config$"
                    match="/configuration/appSettings/add[@key='url']/@value" />
  </parameter>
</parameters>

Create MSDeploy package during build (Visual Studio Build/MSBuild task):

enter image description here

/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true  /p:WebPublishMethod=Package /p:PackageLocation="$(build.artifactstagingdirectory)" /P:PackageTempRootDir=""

Then, it will generates these files:

enter image description here

Content of xx.SetParameters.xml:

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

<parameters>

<setParameter value="" name="email"/>

<setParameter value="" name="url"/>

<setParameter value="Data Source=old string" name="DefaultConnection-Web.config Connection String"/>

</parameters>

Override Parameters of WinRM-IIS Web App Deployment task:

enter image description here

name="DefaultConnection-Web.config Connection String",value="new connectionstring"
name="email",value="[email protected]"
name="url",value="newurl"
like image 175
starian chen-MSFT Avatar answered Dec 09 '25 02:12

starian chen-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!