Setting Environment Variables prior to build
I am using Visual COBOL v2.3 on Red Hat Enterprise Linux 64 bit. I am trying to execute a script which contains the setting of various environment variables required during build. I have tried to use the build configuration Events by both sourcing the script or simply executing the script. In both cases the environment variables are not set at build time. Setting environment variable one at a time within the project will not work because the script is built dynamically. How can this be accomplished?
RE: Setting Environment Variables prior to build
Setting variables in a sub-process doesn't work because environment variable settings are inherited by child processes, but not propagated up to parents. So they only affect the child process and its descendants.
Visual Studio projects are executed by MSBUILD, or the same processor running under the IDE. There's nothing in stock MSBUILD that sets environment variables, as far as I know.
Here's an old StackOverflow post that shows how to add a task that sets an environment variable:
There's also a NuGet package for it:
That could be adapted to read a file (the one you build dynamically) and apply the settings it finds in it. It's not a trivial change, but it's doable.
Another alternative would be to create a script that 1) processes your settings and 2) invokes the COBOL compiler. Then use that from Makefile projects. But that gives up the advantages of using COBOL projects.
Or build from outside the IDE using a script like this:
msbuild myproject.cblproj (or mysolution.sln)
If you want to build from the IDE, you could create a makefile project that runs that script. There are various options for msbuild that you can use to set the build configuration (debug/release), etc.