user76293
user76293

Reputation: 569

Avoiding too many configurations for a Visual Studio project

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...

Upvotes: 2

Views: 1360

Answers (3)

si618
si618

Reputation: 16858

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.

Upvotes: 1

please delete me
please delete me

Reputation:

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.)

Upvotes: 0

idstam
idstam

Reputation: 2878

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.

Upvotes: 0

Related Questions