views:

68

answers:

3

I have a solution with 4 projects inside. What I want to be able to do is to change the order of the batch build (right-click solution Batch Build...). I have configured the Build Order, but this seems to make no difference.

Currently, it seems to just list them in the order they appear in the solution explorer, but they have dependencies of either other in a different order. For example:

Solution
   - Project1
   - Project2
   - Project3
   - Project4

But the dependencies mean it needs to build in this order:

Solution
   - Project4
   - Project2
   - Project3
   - Project1

Is this possible and, if so, how?

+3  A: 

Did you try Project Dependencies? Right click on your solution, choose Project Dependencies, right below Build Order. It let's you choose which projects depend on which. This affects the build order so it shouldn't really make a difference.

How exactly do you determine that the build order is not correct? One way would be to check the output pane when you do a full compile. If the order is correct here then the order isn't wrong, it's just that your dlls aren't being copied into the right folders at the right time.

How are the projects dependent, by library reference? When adding references between project, make sure you're using the Project tab, and not browsing to the dll because then you need to copy the dll between directories after compile.

Martin
Yes - the dependencies are configured correctly and each has the correct references
pm_2
How do you know that they are not building in the correct order?
Martin
Because after I set-up the dependencies, I need them to build in that order: i.e. the one that has no dependencies first, and the one that it dependent on that second, and so on...
pm_2
@pm_2 Martin is asking how you know your build order isn't working. You're still justifying why you need a specific build order, and we understand why. I don't get why fixing your project dependencies isn't enough. I'll post an "answer" since an image explains everything.
Dave
@pm_2 Have you tried clearing the building directory and the rebuilding the solution? VS will use assemblies that exist in the build directory before building them again. Clearing the directory should help you answer @Martin's question.
Mike Chess
pls read my edit.
Martin
+1  A: 

This should explain everything... Like Martin said, you just need to change your project dependencies, because VS is thankfully smart enough to figure out the build order based on them. That's why you can't have circular references in your project dependencies... VS complains because it knows it won't be able to satisfy the requirements of both projects.

alt text

UPDATE

The Project Dependencies definitely determine the build order. Can you post a zip of your solution and projects? I need to see this for myself. :) But for kicks, I made a project like what you have outlined:

Here are my project dependencies:

Project 1 - main app

alt text

Project 2 - depends on Project 4

alt text

Project 3 - depends on Project 2

alt text

Project 4 - no dependencies

alt text

My batch build screen:

alt text

And my output window -- note the build order. Although my Project 1 is really named StackOverflow_BatchBuild, Project 2 was not built first -- Project 4 was.

------ Build started: Project: Project4, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Project4.dll /target:library Class1.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
Project4 -> C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\Project4\bin\Debug\Project4.dll
------ Build started: Project: Project2, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\Project4\bin\Debug\Project4.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Project2.dll /target:library Class1.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
Project2 -> C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\Project2\bin\Debug\Project2.dll
------ Build started: Project: Project3, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\Project2\bin\Debug\Project2.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Project3.dll /target:library Class1.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
Project3 -> C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\Project3\bin\Debug\Project3.dll
------ Build started: Project: StackOverflow_BatchBuild, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\Project3\bin\Debug\Project3.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\StackOverflow_BatchBuild.exe /resource:obj\Debug\StackOverflow_BatchBuild.Properties.Resources.resources /target:winexe Form1.cs Form1.Designer.cs Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs

Compile complete -- 0 errors, 0 warnings
StackOverflow_BatchBuild -> C:\Code\trunk\vs2008\Scratch\StackOverflow_BatchBuild\bin\Debug\StackOverflow_BatchBuild.exe
========== Build: 4 succeeded or up-to-date, 0 failed, 0 skipped ==========
Dave
+1  A: 

Are these C++ or C# projects? If they're C++ projects, are they dependent on the final output (e.g. .LIB files)? Or are they dependent on intermediate files (.H files generated from .IDL files, e.g.)?

Visual Studio will parallelize C++ projects, except at the final linking stage, where it'll deal with the dependencies. If you've got intermediate dependencies, you'll need to configure these appropriately, so that it knows not to parallelize those steps.

Roger Lipscombe