How to substitute configSource for connection strings file during relase build? - azure

I want to develop a pipeline for a .net web app using Azure tfs. I used the IIS Web Deploy template/utility already provided for such deployments. In the release pipeline, I am using XML variable transformation. But one issue I am facing is, that in the project, I have multiple .config files and I have included them in my web.config file as follows
<configuration>
<connectionStrings configSource="None"/>
<appSettings file="None">
</appSettings>
Based on the release for different environments, I perform variable substitution during the release. For example, a folder app_data contains app_sttings_*.config files and file variable does get replaced. But I am having an issue with the connection String file, I can not get configSource to change during release.
Am I doing this wrong or missing a step?

Since the configSource attribute cannot be replaced by the IIS Web App Deploy task. You can use the extension tool Magic Chunks to replace the configSource value.
You can install Magic Chunks extension in your azure devops organization. And add Config transformation task before IIS Web App Deploy task to replace the configSource value.
First you need to define a variable (eg. configSource) to hold configSource value in the Release Pipeline variables section. Then configure the Transformations Section of Config transformation task as below
{
"configuration/connectionStrings/#configSource": "$(configSource)"
}
There is another Replace Tokens task that can replace the configSource value. You can check it out here.
It said in the IIS Web App Deploy task that Variables defined in the Release Pipeline will be matched against the 'key' or 'name' entries in the appSettings, applicationSettings, and connectionStrings sections of the config files. Maybe that is the reason that configSource cannot be replaced by the IIS Web App Deploy task.
See File transforms and variable substitution reference for more information.

Related

Azure Web Job App.Config Transformation not working in TFS Release pipeline

I have an azure web job that I am deploying onto a test environment using TFS Release pipeline. Most of my configuration settings are in the Config settings of App Service Web app except the WCF end point section which is in the app.config.
Here are the settings I have on both the solution as well as build/release pipelines -
Kept the config files (app.config, app.release.config, app..config) of "Content" build action.
Removed the <DependentUpon>.
Verified the config transform files are in the drop file in the same
directory
".....\Local\Package\PackageTmp\app_data\jobs\continuous\JobName"
On the build pipeline I have disabled the config transformation using
/p:TransformWebConfigEnabled=false
On the release pipeline I am using "Azure App Service deploy" version
4.* with XML Transformation enabled.
But somehow, the deployed JobName.exe.config doesn't get transformed with neither app.release.config nor app.environment.config.
Could someone help me on what I am missing here? Thanks in advance.
But somehow, the deployed JobName.exe.config doesn't get transformed
with neither app.release.config nor app.environment.config.
Please check Configuration transform file naming conventions:
XML transformation will be run on the *.config file for transformation configuration files named *.Release.config or *..config and will be executed in the following order:
*.Release.config (for example, fabrikam.Release.config)
*.<stage>.config (for example, fabrikam.Production.config)
For example, if your package contains the following files:
Web.config,
Web.Debug.config,
Web.Release.config,
Web.Production.config
and your stage name is Production, the transformation is applied for Web.config with Web.Release.config followed by Web.Production.config.
To sum up:
It's expected behavior that your JobName.exe.config doesn't get transformed. Cause the XML Transformation options is used to transform your app.config file with app.release.config. (You can check content of your app.config file, it should be changed.)
To get a more powerful transform task, consider using File Transform task.

How to apply config transforms for multiple servers in an environment?

Azure DevOps XDT Transform tasks allow you to build release profiles that transform the base config file with settings that are specific to each environment, such as a connection string that points to different db servers for different environments. The app.dev.config file has transformations for the dev environment, app.qa.config for qa, etc, which are applied during the deployment to the base app.config file.
I need to take this one step further and deploy custom config files for each individual server in a load balanced environment. For example, the DEV environment has two servers dev1.mysite.com and dev2.mysite.com that are load balanced by dev.mysite.com. Each of the two servers needs specific settings in the config file deployed to that server.
I don't (yet) see a way in Azure DevOps to do this. Part of the solution might be to set up variables with the setting that needs to be applied to each environment/server but I haven't figured out how to apply the correct variable to each config.
You can use task Magic Chunks to apply the variable to each config.
You can search for Magic Chunks task in your pipeline and install it to your organization. Then add Config transform task before the deployment task to update the config file with specific setting. For below example settings of magic chunk task:
As above screenshot shows, You can reference your pipeline variables in the tasks.
There are other extension tasks like RegEx Find & Replace you can use to replace the variables in the config files.

Setting the environment for XML transformation in an Azure App Service Deploy task

I'm using an Azure DevOps Pipeline to release an ASP.NET MVC system to an Azure Web App.
I've configured the build not to apply the XML transforms, so I can apply them later, during the release step, and the same build artefact can be released to multiple environments.
The build works fine, and I end up with an artefact containing an untransformed web.config, and the environment-specific transform files.
The Azure App Service Deploy task has a check-box called XML Transformation, which displays the following help text:
The config transforms will be run for *.Release.config and
*.<EnvironmentName>.config on the *.config file. Config transforms will be run prior to the Variable Substitution. XML transformations
are supported only for Windows platform.
At the moment I'm trying to set up a release into a test environment, but the Web.Release.config is being applied, rather than the Web.Test.config. I've searched everywhere I can find for a place to define the environment to make the release use the test config, but I can't find anywhere.
There's a similar question on GitHub which shows the following screenshot:
Unfortunately mine doesn't look like that:
Am I trying to do the right thing? If so, where do I set the environment?
You need to make sure your stage name is just 'Test' and not 'Deploy EMS to Test', reference here.

Visual Studio Team Services Web.Config substitute variables

Before I was shown Octopus Deploy I thought that environment dependent appSettings should be a part of Build Configuration in project properties.
Now in times of software as a service it is a deployment process that buckles everything up.
I want my environment configuration in release process to just open web.config and substitute appsettings and connection strings based on variable names i defined for the release definition.
How can I do it? The closest I could get was Magic chunks. The problem with it is that I have to give it a json with the mapping and I have to define it for each environment separately, so it makes no use of environment variables, really, or at least you have to define it in "enviroment variables" section and then, again, in each process of environment.
You can use the "Tokenizer" task in "Release Management Utility tasks" extension or "Replace Tokens" task.
These tasks can replace the strings in a file with the custom variables in definition.

Display Visual Studio Team Services Release Name within web app

I'm deploying a web app to Azure using Visual Studio Team Services to build and then release.
During release I'm replacing tokens within the web.config file with environment variables I have setup within the release definition for each environment, staging, production etc.
I have set the Release Name Format to include the build number and release number using the following:
$(Build.BuildNumber).$(rev:r)
I know Release.ReleaseName is provided as a pre-defined global release variable, but how can I access this Release.ReleaseName variable within my app to display it in a footer?
Usually, you can use Tokenization build / release task to transfer the value of a variable into web.config file.
But since the variable you want to use is filled with the value of another variable, you need to add an additional powershell step to do this.
Following are the steps for you reference:
Create a new variable.
Change the content that you want to replace in web.config to __Eddie__.
Add a powershell step to set the value of "Eddie" to "Release.ReleaseName".
Add a Tokenization step to replace the __Eddie__ in config.
Now, when you start the release, the content in web.config will be replaced by the value of Release.ReleaseName.

Resources