1

I created a release definition on Visual Studio Team Services for my Windows console application. This app runs on a Virtual Machine so I basically perform the deployment using a Windows Machine File Copy task.

Now I need to create two environments (stage and production) and each of these environments must use different app.config variables.

Recently, I have successfully performed this transformation for a web app using the Azure App Service Deploy XML Variable Substitution. But this is not an available option for file copy task.

How can I make this work?

Igor Kondrasovas
  • 1,479
  • 4
  • 19
  • 36

2 Answers2

1

You can do it with Replace Tokens extension, then copy files.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • I don´t see exactly how this would work. At the output folder of my console app there will be the "myappname.exe.config" file that contains the "release" version of my build, from the build automation. How can I set up the task to replace the correct variables? Before using Continuous Deployment I had a special .config version for stage, release, etc that was loaded conditionally on the .csproj. I have no idea how to set this task to make this happen. Thank you. – Igor Kondrasovas Sep 29 '17 at 15:04
  • this article (http://www.visualstudiogeeks.com/DevOps/replace-appsettings-token-configfiles-build-release-tfs-vsts) made things more clear. Thing is is that I still need a valid app.config for my devenv. There is also a XDT Transform Task I could use, but how can I reference this XDT file from my release definition? Will it have to be added to the output directory as a content file? – Igor Kondrasovas Sep 29 '17 at 15:18
  • By default it replace the #{variable1}# to the value of variable1. For example, 1. there is ` ` section in App.config. 2. Add envVariable variables with corresponding value to stage and production release environments. 3. Add Token Replace tasks to these environments – starian chen-MSFT Oct 02 '17 at 01:30
  • On the other hand, you also can use Tokenizer task, refer to [Using Tokenization (Token Replacement) for Builds/Releases in vNext/TFS 2015](https://dustinoprea.com/2016/05/06/using-tokenization-token-replacement-for-buildsreleases-in-tfs-2015/) – starian chen-MSFT Oct 02 '17 at 01:31
  • Hi @starain-MSFT I think using XDT Transform Task would help me replacing my working app.config with the tokens I would be setting on the environments. I think my doubt here is more basic. On the XDT Transform Task, how do I reference my config files? Should I refere to the source files? On the samples, it uses the working directory... Maybe I will open a new thread about this question specifically. – Igor Kondrasovas Oct 02 '17 at 07:26
  • You just need to refer to the config file, so the working folder can be the path of your config file (.config file). – starian chen-MSFT Oct 02 '17 at 07:41
  • @IgorKondrasovas I have the same scenario as you. Did you figure out a good solution? – getpsyched May 23 '19 at 11:58
  • @getpsyched unfortunately still did not make any progress on that. Need to check if the last comments work for me. – Igor Kondrasovas May 23 '19 at 12:34
  • @IgorKondrasovas Ok, I used the File Transform (Preview) task from Microsoft in my release pipeline to modify the XML config file. Please try that if you are still looking for a solution. – getpsyched May 23 '19 at 12:56
0

You can use the File Transform task from Microsoft in order to replace the environment variables in the XML config file.

This task both updates tokens and replaces them which means that you only need this single task in addition to the Copy Files task in your case.

getpsyched
  • 147
  • 2
  • 15