Click here to Skip to main content
15,913,055 members
Articles
Tip/Trick
(untagged)

Organizing Environment Variables

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
10 Nov 2015CPOL2 min read 9.3K   6   4
Successfully organizing your environment variables for multiple projects and for multiple versions of tools.

Introduction

The software industry I'm in requires me to have different versions of the same tools, depending on which project I am working with. Most of these tools requires me to configure some environment variables. When I start working on a different project, I have to change some environment variables to point to other versions of the tools I'm using. My environment variable configuration can get very cluttery and unorganized, very quickly if I'm not careful. I've found a solution to organize my environment variables in such a way that switching between projects happens seamlessly, without the need to re-configure my environment variables every time.

Problem

Assume I have the following projects and tools:

PROJECT_A requires TOOL_A ver 1.1 TOOL_B ver 5.123 and TOOL_C ver 9.12.

PROJECT_B requires TOOL_A ver 2.0 TOOL_B ver 5.123, TOOL_C ver 7.12. and TOOL_D ver 0.6.

PROJECT_C requires TOOL_B ver 6.123, TOOL_C ver 8.8 and TOOL_E ver 3.3.

Everytime I switch between these projects, I need to re-configure the environment variables to point to the correct locations and/or update it with the correct value.

Solution

Intelligent use of environment variables, here is how:

Create a environment variable per project:

In Pictures:

Image 1

In Words:

Variable: aPROJECT_A

Value: c:\TOOL_A\VER_1_1;c:\TOOL_B\VER_5_123;c:\TOOL_C\VER_9_12

Variable: aPROJECT_B

Value: c:\TOOL_A\VER_2_0;c:\TOOL_B\VER_5_123;c:\TOOL_C\VER_7_12;c:\TOOL_D\VER_0_6

Variable: aPROJECT_C

Value: c:\TOOL_B\VER_6_123;c:\TOOL_C\VER_8_8;c:\TOOL_E\VER_3_3

Now add another environment variable that looks a bit different - With this environment variable you select which project you are working on by setting the value of it equal to the project you are working on:

In Pictures:

Image 2

In Words:

Variable: bSELECT_PROJECT

Value: %aPROJECT_B%

Then add the'bSELECT_PROJECT' variable to the 'path' environment variable:

In Pictures:

Image 3

In Words:

Variable: Path

Value: c:\xxx\xxx;c:\yyy\yyy;c:\zzz\zzz;%bSELECT_PROJECT%;

Now you can switch between projects that uses the same software tools but different versions of it seemlessly by just changing the bSELECT_PROJECT environment variable value to the project you are working on.

You'll notice I've put an 'a' infront of the projects and a 'b' unfront of the select project environment variables. This is to ensure the correct order of the environment variables. The environment variables are alphabetically ordered and if the project environment variable name, which is referenced by the select project environment variable, comes after the select project environment variable in the alphabet, it won't work.

Conclusion

This is but one way of managing your environment variables. It works for me. I'm sure with a little bit of tought, more environment variable problems could be solved by building on this method of environment variable management. Let me know if you've found some other tricks to add to this.

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer SAAB AB
South Africa South Africa
Real coders copy and paste, :-P

!!! Please Vote !!!

Comments and Discussions

 
SuggestionUse project variables (User Macros) instead Pin
Stefan_Lang16-Nov-15 20:05
Stefan_Lang16-Nov-15 20:05 
QuestionI just use batch files Pin
Zebedee Mason12-Nov-15 6:40
Zebedee Mason12-Nov-15 6:40 
QuestionDifferent environments Pin
Wendelius10-Nov-15 4:31
mentorWendelius10-Nov-15 4:31 
AnswerRe: Different environments Pin
R. Erasmus10-Nov-15 19:42
R. Erasmus10-Nov-15 19:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.