views:

306

answers:

3

The short version of my question is how do I change the build order of projects in my solution without being forced to set one project as a dependency of the other?

In my solution, I've got 2 projects:

1.) An executable written in C
2.) A static library containing unit tests using the CUTest framework.

I've got 4 build configurations:

1.) Debug - I want only the exe in debug mode. The static lib project is un-selected so it won't build.
2.) Release - I want only the exe in release mode. The static lib project is un-selected so it won't build.
3.) Debug with Unit Tests - Want the static lib built, then the exe since it depends on the lib in this case.
4.) Release with Unit Tests - Ditto #3, just in release.

Because the executable is dependent on other libs and dlls not in the solution, I've got all those listed out as additional dependencies in the linker settings. In the unit test build configurations, I've got the static lib also included in the executable's dependency list.

Now here's the rub. The only way I've found so far to change the build order and make sure that the static lib is built before the exe is to right-click on the solution and select build order. In that dialog box, it says that I must use the dependencies tab to change the build order. This makes sense. However, if I mark the executable as depending on the static lib, it automatically adds the static library as a linker dependency of the executable. This is fine for the unit test build configs. In the non unit test build configs, however, it tries to link in the static lib which, if I've done a clean before the build, has been deleted and can't be linked in because I don't build it in those configs (nor do I want it linked in in those cases).

That being said, is there a way to change the build order without marking dependencies? I'd want to set the build order for the unit test configs to make sure the static lib was built first.

+1  A: 

I would take a look at NAnt. It may be possible to build an ant script to solve your problem.

http://nant.sourceforge.net

Dan
I see that NAnt would be an option, but since it's not currently used on my team using it here would force the rest of the team to install it if they needed to work on this project later. I'll definitely take a look at it since it looks helpful.
Taylor Price
+2  A: 

You can disable the automatic inclusion of library dependencies.

In your exe's property page:

Linker -> General -> Link Library Dependencies -> No

This allows you to specify project dependencies and thus build order without the static library being linked in.

Soo Wei Tan
Thank you very much. I hadn't noticed that setting before. That works perfectly.
Taylor Price
A: 

'Per configuration dependencies' may be an answer. It will allow to specify that the lib is a dependency of the executable for only the configuration where this makes sense.

Xavier Nodet
What you're suggesting is exactly what I'd want, but I haven't seen a way to set inter-project dependencies in VS per configuration. That's why I've put all of the libs/dlls on Linker->Input->Additional Dependencies for each configuration. Soo Wei Tan's suggestion above works great in this setup.
Taylor Price