9

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?

zzz
  • 335
  • 3
  • 8
  • 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 Oct 08 '12 at 07:08
  • 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 Oct 08 '12 at 07:11
  • 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 Oct 08 '12 at 07:18

4 Answers4

3

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.

Community
  • 1
  • 1
Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
  • 1
    Thanks Hans. All the files including the custom build one and the generated C++ files are in one project. Hence my question was about compile order, not project build order. I guess I can move all the custom build files to a new project and make the original project depend on it, but it does not look like a nice solution especially given that it was working fine in VS2005. But if there is no other alternative I will be forced to do it this way. – zzz Oct 08 '12 at 22:23
  • Hmya, I guessed that the "note to other readers" might apply. – Hans Passant Oct 08 '12 at 23:18
1

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.

Sandy
  • 11
  • 1
1

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.

  • Thank you but I have moved on from VC2010 and actually the VC build order is correct. I wrongly assumed it is the reason so titled this question this way. You can see from my answer that the actual reason was the change in the way custom builds steps are executed. – zzz Aug 23 '15 at 23:37
0

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.

zzz
  • 335
  • 3
  • 8