简体   繁体   中英

How to control order of Batch Build → Build All

I have a C++ solution with 4 projects and 24 configurations. The projects are cryptest , cryptlib , cryptdll and dlltest . And then there's a partial cross product of x86, x64, debug, release, DLL export, and DLL import.

There's a not-so-apparent dependency that I can't seem to express under the UI or by modifying the project files by hand. The dependency is all the DLL related projects depend upon cryptest, Release Win32 .

Visual Studio allows us to build all configurations by selecting the Build menu, and then Batch Build... → Select All → Build . When I perform a Build All , the first configuration built is:

------ Build started: Project: cryptlib, Configuration: DLL-Import Debug x64 ------
Performing Custom Build Step
 Assembling: c:\Documents and Settings\cryptopp-5.6.3\x64masm.asm
Performing Custom Build Step
Compiling...
pch.cpp
...

As can be seen above, the machinery chooses cryptlib, DLL-Import Debug x64 as its first choice. I want the following order:

  • cryptlib, Release Win32
  • cryptest, Release Win32
  • Don't care about remaining 22....

The problem is I cannot tell Visual studio that all Win32 and x64 DLL projects depend upon the Win32 cryptest .

How can I control the order of Batch Build → Build All ?


Currently I have to run through Build All twice. The first ends with:

========== Build: 20 succeeded, 4 failed, 0 up-to-date, 0 skipped ==========

The second run ends with:

========== Build: 4 succeeded, 0 failed, 20 up-to-date, 0 skipped ==========

When reordering the solution file's GlobalSection(ProjectConfigurationPlatforms) with a text editor (and placing them in the exact order I want), these are the kind of warm and fuzzy results I encounter. The 24 configurations will build with Build All under Visual Studio 2005, but Build All does nothing (literally, nothing) under Visual Studio 2008 after testing an upgrade.

And when I manually try to build a project (right click project, then Build ), I get a result like:

1>------ Skipped Build: Project: cryptlib ------
1> 
2>------ Skipped Build: Project: cryptest ------
2> 

With no reasons or explanations. It sure would be nice if Visual Studio provided a log file in an attempt to decipher the behavior.


A related issue is Visual Studio selects << some project >> as the default Startup project with no declarative way to change it . That means a particular project needs to be the first one listed in the solution file, and that cannot change.


I'm having a hard time finding a solution that is amicable to both Visual Studio 2005 (how the source files are distributed) and a post-Visual Studio 2010 upgrade (how some folks use it).

I can kind of find some information on the subject, like Project settings changes with VS2010 from a blog. But its not really clear how to effect a dependency change as described above, and the blog only applies to VS2010 or above.

Create a x86 and x64 project for cryptest and cryptlib.

For each x86/x64 project pair, use Add As Link to link to all the files in the other project so you only have just one copy of each file.

...links shown with the red arrows...

解决方案

Configuration Manager

Use Configuration Manager to build x86 only for the x86 projects, and x64 only for the x64 projects.

Also use the dropdown for each Platform and remove the extra platform that does not apply to the corresponding project.

Also ensure that for x86 builds you are not building x64 targets, and for x64 builds you are not building x86 targets by unchecking the appropriate Build checkbox.

配置管理器

Dependencies

Create dependencies as such:

  • cryptlib32 depends on nothing
  • cryptest32 depends on cryptlib32
  • cryptlib64 depends on cryptlib32 and cryptest32
  • cryptest64 depends on cryptlib64
  • all your remaining projects depend on cryptlib32/64 and cryptest32/64 as appropriate

...one example...

项目依赖

Result

This should produce the results you want.

Testing

In my test project, this worked as expected. I named all my code with the prefix ClassLibraries , and just added lib and test on the end to mimic your config, and final is just any project after the first two projects...

The x86 lib and test build first, x64 lib and test next, and all the other stuff follows...

------ Rebuild All started: Project: ClassLibraryLib32, Configuration: Debug x86 ------
  ClassLibraryLib32 -> C:\Users\Kory\Source\KoryG-Code\Solution1\ClassLibraryLib32\bin\x86\Debug\ClassLibraryLib.dll
------ Rebuild All started: Project: ClassLibraryLib32, Configuration: Release x86 ------
  ClassLibraryLib32 -> C:\Users\Kory\Source\KoryG-Code\Solution1\ClassLibraryLib32\bin\x86\Release\ClassLibraryLib.dll
------ Rebuild All started: Project: ClassLibraryTest32, Configuration: Release x86 ------
  ClassLibraryTest32 -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryTest32\bin\x86\Release\ClassLibraryTest.dll
------ Rebuild All started: Project: ClassLibraryTest32, Configuration: Debug x86 ------
  ClassLibraryTest32 -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryTest32\bin\x86\Debug\ClassLibraryTest.dll
------ Rebuild All started: Project: ClassLibraryLib64, Configuration: Debug x64 ------
  ClassLibraryLib64 -> C:\Users\Kory\Source\KoryG-Code\Solution1\ClassLibraryLib64\bin\x64\Debug\ClassLibraryLib.dll
------ Rebuild All started: Project: ClassLibraryLib64, Configuration: Release x64 ------
  ClassLibraryLib64 -> C:\Users\Kory\Source\KoryG-Code\Solution1\ClassLibraryLib64\bin\x64\Release\ClassLibraryLib.dll
------ Rebuild All started: Project: ClassLibraryTest64, Configuration: Release x64 ------
  ClassLibraryTest64 -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryTest64\bin\x64\Release\ClassLibraryTest.dll
------ Rebuild All started: Project: ClassLibraryTest64, Configuration: Debug x64 ------
  ClassLibraryTest64 -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryTest64\bin\x64\Debug\ClassLibraryTest.dll
------ Rebuild All started: Project: ClassLibraryFinal, Configuration: Release x86 ------
  ClassLibraryFinal -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryFinal\bin\x86\Release\ClassLibraryFinal.dll
------ Rebuild All started: Project: ClassLibraryFinal, Configuration: Release x64 ------
  ClassLibraryFinal -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryFinal\bin\x64\Release\ClassLibraryFinal.dll
------ Rebuild All started: Project: ClassLibraryFinal, Configuration: Debug x86 ------
  ClassLibraryFinal -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryFinal\bin\x86\Debug\ClassLibraryFinal.dll
------ Rebuild All started: Project: ClassLibraryFinal, Configuration: Debug x64 ------
  ClassLibraryFinal -> c:\users\kory\Source\KoryG-Code\Solution1\ClassLibraryFinal\bin\x64\Debug\ClassLibraryFinal.dll
========== Rebuild All: 12 succeeded, 0 failed, 0 skipped ==========

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM