VSTS Release - Define custom variable in web.confi

2019-04-26 16:43发布

问题:

I am trying to replace an appSetting at release time using VSTS Release. All post on the web refer to the old release management tool or refer to the new one but mention the replace tokens task. This task does not exist so I presume it is built in. I have set up my web.config (MyVar) and set up my environment variables but nothing gets replaced.

And here is my release:

I apologise if I am being stupid but I just can't work this out, mostly due to out of date documentation.

Update 2: Ok so after some help from a couple of people I am now on the right track with this. I have added the Colin's ALM tokenisation task: https://marketplace.visualstudio.com/items?itemName=colinsalmcorner.colinsalmcorner-buildtasks

However, it doesn't work.

Here are a couple of screen shots: Note that in the screen shot, I know it is disabled. This is just until I can get it fixed.

In the following screen shot, I see the only a few locations to choose where the tokenisation occurs. Does this look correct or should I be able to see the Web.Config in which I want the tokens to be replaced?

As I said, the tokenisation didnt work.

I tried a couple of changes to try to get it to work.

Change 1: Point to a zip file in above acreen shot. My release worked but it had not deployed any of my web site files to the Azure server. NONE, at all.

Change 2: Point to another file CustomerPortal.SetParams.xml

(Note: at this point I was just trying random file to try and get anything to work) My release worked but nothing happened with regard to tokenisation.

Here is part of my log:

As you can see, all my files from my website are not there even though the release was successful:

Any help would be appreciate.

回答1:

This can be tricky if you're coming from the older Release Management or the Web Deploy tasks that would replace tokens from Web.Release.config and replace lines in your normal web.config.

The solution I have implemented is to use two tasks; one task to replace the tokens of the Web.Release.config (not web.config because I want to run locally without hassles), and a second task to 'move' the Web.Release.config file over your web.config. I'm on windows servers so your implementation may need a tweak but the process would be similar.

IMPORTANT: Your Web.Release.config should be a full clone of your web.config, with the tokens in place. It cannot remain a partial config like it may have been when using the old web deploy transform functionality.

Using cmd.exe, the arguments are: cmd /c move /y "YOUR_BUILD\drop\YOUR_PROJECT\Web.Release.config" "YOUR_BUILD\drop\YOUR_PROJECT\Web.config"



回答2:

There is no built-in token replacement in the VSTS Release Management. Injecting values into a web.config is a deployment task, and VSTS Release Management is deployment tool agnostic.

If you need to inject values into configuration files (or otherwise alter them) at the time of deployment, that's something you can build into your deployment scripts.



回答3:

There is currently no built-in task for replacing token values. You could either write a custom script to handle this or use one of the existing 3rd party task available, like eg the Replace Tokens task Colin's ALM Corner Build & Release Tools .