views:

473

answers:

3

I'm currently porting a large Linux project to Visual Studio. The project depends on a number of third-party libraries (Python, MPI, etc.) as well as a couple of in-house ones. But it can also be built without these libraries, or with only a few of them. So I don't want to create a different configuration for each possible combination, e.g. "Parallel with Python", "Parallel without Python", etc. There are just too many combinations. Is this a situation where I could use MSBuild?

Edit: One possibility I considered is to create a bunch of .vsprops files, but this is essentially the same as creating a bunch of different configurations.

Edit: Maybe CMake is more what I'm looking for? I'd love to hear from any CMake users out there...

A: 

If you right-click the solution in Visual Studio and select Configuration Manager you can create build targets for each configuration.

You can select between those targets with a combo box in the toolbar if you have the default settings.

Those targets can also be selected when using MSBuild just as you can choose between Release and Debug.

idstam
That doesn't answer my question. I'm building the same projects regardless of which external libraries are used, e.g. if I want to use Python I don't build Python as part of my project, I simply #define HAVE_PYTHON and include/link the necessary files.
A: 

There's no good solution to this that I'm aware of. The IDE seems to require a configuration for each set of command line arguments to the tools. So if N different sets of arguments are required -- as it sounds like the case is here -- N different configurations will be required. That's just how the IDE works, it appears.

Unfortunate, but one rarely wins in a fight against Visual Studio, so I personally have always given in and created as many configurations as needed. It's a pain, and it's fiddly, and yes the IDE should ideally provide some better mechanism for managing the combinations -- but it's doable, just about, and it doesn't actually take as long to set up as it feels like at the time.

(As I understand them, .vsprops can take some of the pain away by allowing easy sharing of configuration settings between configurations. So those miniscule text boxes in VS are only used to set up the settings that differ between configurations. This may make them still worth investigating. This isn't something I've used myself yet, though; only discovered it recently.)

brone
Looks like until MSBuild supports Visual C++ projects in VS 2010 this is the only solution.
+1  A: 

One approach could be to conditionally reference your libraries using the Condition attribute of every assemblies Reference element (Python, MPI, etc).

This could separate your libraries from the configuration and platform properties, and allow you to build them by default, or conditionally using MSBuild properties.

So in your csproj:

<Reference Include="YourPythonLibrary" 
           Condition="$(BuildType) == '' Or $(BuildType) == 'TypeA'" />
<Reference Include="YourMpiLibrary" 
           Condition="$(BuildType) == 'TypeA' Or $(BuildType) == 'TypeB'" />

That includes Python by default and MPI only if the correct build type is set. Wouldn't matter what the configuration or platform is set as, and you could adjust the boolean logic to suit each library for each of your build types.

MSBuild /p:BuildType=TypeA
MSBuild /p:BuildType=TypeB

It would be nice to use some form of bitwise operation on the condition, but i'm not sure that is possible in MSBuild?

Note: Doesn't have to a Reference element, if it's just included as Content this approach will still work.

Si
Will this work for Visual C++ projects? I've never used MSBuild before, so I don't really know any details about it...
Oh, I thought you were talking about C# project, sorry! no idea about C++, the MSBuild schema is totally different, so you would have to hunt through http://msdn.microsoft.com/en-us/library/y4sy8216.aspx and see if you have the equivalent of "Condition" attribute for your particular reference type.
Si
Just had a quick look and "UseInBuild" attribute is a boolean of "AssemblyReference" element, worth a shot?
Si
MSBuild will be supported in Visual Studio 2010 for Visual C++ projects.
Michael Kelley