views:

111

answers:

2

I have a large project made of many C++ and C# projects, and a MSBuild (3.5) script to build the whole thing. This script is based on the VCBuild (C++ projects) and MSBuild (C# projects) tasks. It is regularly executed by a Continuous Integration server.

I want to be able to select a specific Windows SDK (v6.0A, v7.0, v7.1...) to be used for compilation. As I have many branches in my repository that would ultimately need a different SDK version, I need a way to select the right one before each compilation.

On my computer, I have been able to setup a batch script that calls the right SetEnv.cmd before launching the MSBuild script. But this solution is not usable on the CI server as the MSBuild script is executed directly.

Do you know of a way to achieve the equivalent of SetEnv.cmd under MSBuild?

+1  A: 

You could create a custom MSBuild task that uses Environment.SetEnvironmentVariable to set the appropriate environment variable values depending on the specified platform SDK version. Check the vcvars32.bat (or vcvars64.bat depending on your target configuration) to see what environment variables need to be set.

Jim Lamb
A: 

I ended up creating a custom MSBuild task that would take a batch file name as parameter, execute the following command line (having batch.cmd as a parameter) :

cmd.exe /E:ON /V:ON /S /C "batch.cmd > nul && SET"

The output is then parsed, and I set the environment variables accordingly for the current process.

This way, I can execute SetEnv.cmd and get the right environment variables in the MSBuild process.

Mac