Simpler Approach
Overview
Here the main objective is to dynamically override settings within the Web.config file, specifically targeting values within the appSettings, connectionStrings, and applicationSettings nodes. This flexibility is crucial to ensure that a single application can seamlessly adapt to different environments by utilizing distinct resources as dictated by pipeline variables. We will consider the name/key attribute within the appSettings, connectionStrings, and applicationSettings nodes as unique.
Given our understanding of the specific nodes requiring modification and the names of the values to be replaced during deployment, we propose a streamlined approach to enhance user experience. Users will supply the node's name/key suffixed with wt _ as the key in the pipeline variable. The corresponding value in the pipeline variable will then represent the actual value to be substituted. This method ensures a straightforward and intuitive process for users managing configuration overrides.
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ClientId" value="19ee6b53-aaeb-4b44-ab99-c100f551f107"/>
<add key="Secret" value="c3b268862bb6af823702144a52b39a1c31dd5441b968d6b5efdb925d6ef5f66d"/>
</appSettings>
<connectionStrings>
<add name="MyDbContext" connectionString="Data Source=127.0.0.1;Initial Catalog=MyNewDatabase;User Id=my_pro_user;PWD=user_pro_pwd" providerName="System.Data.SqlClient"/>
<add name="MySecondDbContext" connectionString="Data Source=129.0.0.1;Initial Catalog=MyAnotherDatabase;User Id=another_user;PWD=another_pwd" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<identity impersonate="true" userName="my_username" password="user_pwd" />
</system.web>
<applicationSettings>
<setting name="TenantId">
<value>4cb65d2a2492ec05e7751b98f9f99d1832809676</value>
</setting>
<setting name="UserId">
<value>12bdf328-baec-4f02-bae2-f0d9e8d464fa</value>
</setting>
<setting name="UserSecret">
<value>3b749cb2390f0a5514995ee027ccb57b50b5c81e5580c54386c23fb23f530d16</value>
</setting>
</applicationSettings>
</configuration>
Example
Updating ClientId in appSettings
<appSettings>
<add key="ClientId" value="19ee6b53-aaeb-4b44-ab99-c100f551f107"/>
<add key="Secret" value="c3b268862bb6af823702144a52b39a1c31dd5441b968d6b5efdb925d6ef5f66d"/>
</appSettings>
To update the ClientId element attribute value to b2998407-8bea-4ad6-a697-fe26e6a06b4e, create a pipeline variable with the key wt_ClientId and the value b2998407-8bea-4ad6-a697-fe26e6a06b4e. Upon execution, the system will locate the ClientId node within the appSettings, replacing its attribute value with the specified key.
Updating MyDbContext ConnectionString in connectionStrings
<connectionStrings>
<add name="MyDbContext" connectionString="Data Source=127.0.0.1;Initial Catalog=MyNewDatabase;User Id=my_pro_user;PWD=user_pro_pwd" providerName="System.Data.SqlClient"/>
<add name="MySecondDbContext" connectionString="Data Source=129.0.0.1;Initial Catalog=MyAnotherDatabase;User Id=another_user;PWD=another_pwd" providerName="System.Data.SqlClient"/>
</connectionStrings>
For modifying the MyDbContext connectionString attribute value to Data Source=127.0.0.1;Initial Catalog=MyNewDatabase;User Id=my_pro_user;PWD=user_pro_pwd, create a pipeline variable with the key wt_MyDbContext and the corresponding value. The system will then identify the MyDbContext node within the connectionStrings, updating its connectionString attribute accordingly.
Updating TenantId in applicationSettings
<setting name="TenantId">
<value>4cb65d2a2492ec05e7751b98f9f99d1832809676</value>
</setting>
When updating the TenantId value, which resides within a value node rather than an attribute, create a pipeline variable with the key wt_TenantId and the desired value 2732c73a-dd32-4718-9d87-04fc1d378a9d. Subsequently, the system will search for the TenantId node within the applicationSettings, updating the inner text of the value node under the corresponding setting node.
Updating userName and password in identity
<system.web>
<identity impersonate="true" userName="my_username" password="user_pwd" />
</system.web>
To update the userName and password attribute to anotheruser and _another_user_pwd of the identity node, create 2 pipeline variables with the key wt_identity_userName and wt_identity_password and the respective values another_user and another_user_pwd. Upon execution, the system will locate the userName and password attributes in the identity node within the system.web node, replacing its attribute value with the specified key.