4

I've set up 3 environments (Debug, Stage & Production) and created a custom variable named testVariable for each environment within the RELEASE tab of my Visual Studio Team Service project as shown here:

enter image description here

I also have a release variable named testReleaseVariable shared by all the enviornments as shown here:

enter image description here

I can't find any documentation on how to set up my ASP.NET projects in VS to use these variables when developing locally as well as when deploying a build so that they can be injected by the Release Manager.

I have both ASP.NET 4.5 as well as ASP.NET 5.0 projects. My question is: What is the best practice for setting up my Web.Config (for ASP.NET 4.5 projects) or my Config.json (for ASP.NET 5 projects) to work with both the enviornment as well as the release configuration variables in VSTS Release Management.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
INNVTV
  • 3,155
  • 7
  • 37
  • 71

2 Answers2

7

The configuration variables can be used in any of the Tasks.

You can use the configuration variable by using the $(configVarName) in any of the tasks.

Note that directly you can use these variables only in the tasks not inside the files like Web.Config.

To use them inside files and replace them with appropriate values, you can use the Tokenizer Task.

More info is available at this blog post

Harshil Lodhi
  • 7,274
  • 1
  • 33
  • 42
  • Thanks Harshil. This is taking me down the right path so I'll mark it as the answer. I'm a little confused why we need to create/upload a custom or 3rd party task for this. Seems like this would be such a common task that it should be built into Release Management? Are you able to shed some details on the thinking here? – INNVTV Dec 06 '15 at 21:55
  • One more question on this Harshil. When creating the new Zip files from the source is it best practice to create a new one for each environment or is it OK to overwrite the previous one? Also I am assuming you should not overwrite the source Build ZIP as you need this to run tokenization on for each environment? None of the examples touch on this aspect and all of the screenshots have the full paths cut off so it is hard to see what naming convention is being used. Thank you! – INNVTV Dec 06 '15 at 22:25
  • @CodeAbundance Yes, I also think that this support should be present by default. We are making some changes to tasks so that this is available as a 1st party task. About the best practice thing, I am not sure which way is the best. I will surely research on this and let you know. – Harshil Lodhi Dec 08 '15 at 02:29
  • Thanks Harshil. Can you also clarify what the difference is between a "Release Varaible" and an "Enviornment Variable" when you are in the Configuration tab of a Release? It's the drop down on the right side. Does the tokenization task use both? – INNVTV Dec 08 '15 at 19:09
  • @CodeAbundance The Release Variable is available on all the environments, it will have the same value for all the environments. While the environment variables are scoped to a environment. So a environment variable can have different values for different environments. – Harshil Lodhi Dec 09 '15 at 16:39
  • Could you say if is it possible to update OS environments (or app settings within app services)? – Serhii Kyslyi Aug 21 '17 at 20:08
1

The vNext VSTS Tokenization task was moved on GitHub and can be found here.

https://github.com/TotalALM/VSTS-Tasks