9
votes

I have recently converted a mid-sized Visual Studio 2005 solution to Visual Studio 2010. One of the projects contains files which are not C/C++ files and are compiled using a batch file running a custom build tool. The output of the custom build step is some C++ files, which must be compiled after that.

The output of the custom build step in the properties for the relevant files is correctly set to the generated C++ files.

The problem is that sometimes VS2010 tries to compile the generated C++ files before the files with the custom build step, which means in a clean build it fails to find the C++ files and fails. If I try building several times eventually it would compile the custom files and then the build will succeed, but this is obviously not a good solution for automated build.

In VS2005 there is no problem building this project, but VS2010 fails to determine the correct compile order from the outputs of the custom build step. Is there another way to force correct compile order in VS2010?

4
What are the files with custom build step? I associate h-files with custom build step in my project, and custom build steps are always executed first, before any .cpp file compilation.Alex F
If your custom build step is executed for .cpp file, you can move all .cpp file code to h-file and include this h-file to empty .cpp file - the same result for compilation, put possibly may help in your problem. Just a guess.Alex F
Thanks Alex, The custom files are with .wsdl extesion. I use a SOAP library to generate some .h/.cpp files with proxy code in them.zzz

4 Answers

3
votes

Visual Studio supports parallel builds, it can build more than one project at the same time. This will not work properly if it cannot properly see the dependencies between projects. A custom build can certainly be a troublemaker here. The number of parallel builds is configurable, setting it to 1 would be a very crude but effective workaround. Tools + Options, Projects and Solutions, Build and Run, "maximum number of parallel project builds" setting.

But don't do that, parallel builds can be a huge time saver. You fix this kind of problem by setting project dependencies explicitly. Right-click the project that uses the generated C++ files in the Solution Explorer window and click Project Dependencies. Tick the check box for the project that produces the C++ files. In case it is relevant to other readers, check this answer for a way to create a project that only does the custom build step and nothing else.

1
votes

Visual Studio 2008 by default executes custom build tools first. The order can be changed via right click menu on project with command "Tool Build Order". This facility is not available in Visual Studio 2010. I do not know of a work-around.

1
votes

Consider using Visual Studio 2010's "Properties >> Configuration Properties >> Build Events >> Pre-Build Event" as the place where you should issue command(s) to build source files that must be compiled first. In the Command Line field, call upon the cl.exe compiler or use a small external makefile to compile those files. Visual Studio will then compile the rest of your project following this initial step.

0
votes

I resolved my problem when I noticed that my custom build step runs for only one file at a time. It runs for the next file on the next build etc. The reason apparently is that my custom build steps are calling a batch file and VS2010 creates one temporary batch file to execute all custom build files. The solution was pointed in this discussion: http://social.msdn.microsoft.com/Forums/en-HK/msbuild/thread/ca392036-ebdb-4812-930e-f90aa445cca5 It is simply to prefix all calls to batch files with a "call" statement, thus not terminating the execution of the master batch file prematurely.