Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app.config transformations in Azure Devops for different environments

I've got a .Net Framework 4.6.1 project, which creates a Windows Service. We want to have this built and deployed by an Azure Devops pipeline. We've successfully created pipelines for all of our .Net Core web services (using the ASPNETCORE_ENVIRONMENT variable and a set of appsettings.{ENV}.json files) but the Windows Services don't seem to play as nicely in terms of providing different configuration for different environments.

I've got XDT transformations working for the App.config XML file. I can right click the files in Visual Studio and "Preview Transform" and it works fine.

What's not clear is how I translate this to the pipeline configuration. The Build task seems to be capable of running the transform but then I'm not sure how we have a different transformation for different Deploy stages. What happens instead is that all environments end up with whatever transformation was applied to the Build Configuration selected as part of the Build step.

I've followed numerous blog posts - including this one, which claims you can have multiple build configurations, but for which I don't seem to have the setting.

What am I missing?

like image 438
Jeremy Gooch Avatar asked Nov 20 '18 15:11

Jeremy Gooch


People also ask

What are the available options for deployment environments provided by Azure?

Environments can include Kubernetes clusters, Azure web apps, virtual machines, databases. Typical examples of environment names are Dev, Test, QA, Staging, and Production.

What is Xdt transform SetAttributes?

The xdt:Transform attribute value "SetAttributes" indicates that the purpose of this transform is to change attribute values of an existing element in the Web.

Which Azure DevOps feature can we use for the deployment to app service?

Web Deploy (msdeploy.exe) can be used to deploy a Web App on Windows or a Function App to the Azure App Service using a Windows agent.


1 Answers

What we do with VSTS which I assume is similar in the newer Azure Devops. We have the transformation add tokens to the config file IE "DefaultConnection": "Server=DBServer;Database=DB;User ID=DBUser;Password=DBPassword;" Then There is a task on the release enviroment called Tokenization which pulls variables set from the release enviorment to replace the underscored tokens.

We use this plugin to do the tokenization step. https://marketplace.visualstudio.com/items?itemName=TotalALM.totalalm-tokenization

like image 108
Ryan Schlueter Avatar answered Oct 20 '22 14:10

Ryan Schlueter