How to set Visual Studio build environment variables

In my gradle build script, I need to set the Visual Studio environment variables by calling the vcvarsall.bat file.

I currently have this specified in a task.

This must be done prior to calling another task so I have this other task dependent on the vcvarsall task.

The problem is that each task is executed in its own shell/process so when I set the Visual studio environment variables, it is only useful for that task - it does not persist into the dependent task.

How can I solve this problem?