Configuration specific constants

Hi Hector @Hector_Pople,

coming back to @wielando 's suggestion:
I really like that idea so much that I did a simple sample to show how it could be used!

Of course it’s only a simple sample to show the principle, it could be even done better with more usability and functionality (for example storing also the batch file inside the project, use the internal system variable with the configuration name, and so on …) - but showing the “how it works” it’s good enough :wink:

Let’s assume we have 2 configurations with different member values inside the constant structure. The task “Program” uses the global constant structure variable named “myConfigConsts”, with variable declared in the global variable file “SetupConst.var” (and type declared in the global typ file “Global.typ”).

image

What we need:

  • 2 “variable file templates” holding the different constant values (“Cfg1Const.txt” and “Cfg2Const.txt”)
  • a batch file for overwriting the “SetupConst.var” with the suitable template file
  • a pre-build step calling that batch file in every configuration

The template files are nothing more then a text file holding the content of SetupConst.var with the wanted constant values:

The batch file overwrites the “SetupConst.var” file with the wanted template file.
Input argument 1 (%1) to the batch file is the Automation Studio project path, argument 2 (%2) is the name of the template file:

And finally, in the configuration dependent pre-build steps the batch file is called with those 2 arguments:

So, when compiling for example configuration “Config2”, the pre-build step changes the “VarConst.var” content via the batch file to the wanted constant values.

Best regards!

3 Likes