9

Given a Solution where:

  • Project P1 has a reference to P2
  • P2 has a reference to P3
  • P3 has reference to P4

When you call msbuild this way:

msbuild.exe /v:m "c:\mysolution\p1\p1.csproj"

msbuild checks all project dependencies is builds dependencies if necessary. The typical output is:

Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

  P4 -> c:\mysolution\P4\bin\Debug\P4.dll
  p3 -> c:\mysolution\p3\bin\Debug\p3.dll
  p2 -> c:\mysolution\p2\bin\Debug\p2.dll
  p1 -> c:\mysolution\p1\bin\Debug\p1.dll

In my case, I know the dependencies exist and are all right.

Is there a way to build only project p1.csproj without verifying dependencies? The solution can be with msbuild or with something else.

Sylvain
  • 19,099
  • 23
  • 96
  • 145
  • I'm wondering....could I call the c# compiler instead of msbuild and pass all the params? Would it be hard to figure out the params to pass even for a large project that has a lot of references and dependencies? – Sylvain Aug 27 '10 at 20:59
  • A related question: http://stackoverflow.com/questions/819031/how-to-decrease-msbuild-times – wmeyer Aug 27 '10 at 21:37
  • Thanks. We already use multi processor builds with msbuild (/m option) and for us, it makes a huge difference: close to 2X faster. – Sylvain Aug 27 '10 at 21:43

5 Answers5

5

you can pass /p:BuildProjectReferences=false to msbuild, which will skip build project refence.. but this has one limitation, if your solution configuration and referenced project's configuration is mismatch, msbuild will failed to resolve referenced project's target output file...

here is a free vs extension package, you can download and try http://visualstudiogallery.msdn.microsoft.com/98de4058-8dc7-435b-9e01-c0f71dace808

vs package: Sharp Build Utility

I'm the author of this extension, i have the same requirement in current work, enjoy this tool...

essentially, this extension can handle above case, which will make a shadow copy of your build project file, change all project reference to dll file reference, and launch msbuild with the shadow project file.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Winston
  • 410
  • 1
  • 6
  • 9
2

What's the goal (why do you care)?

You could use assembly references rather than project references (but beware debug v release path differences).

Brian
  • 117,631
  • 17
  • 236
  • 300
  • I care because in a solution with 100 projects, this step takes very long; 10 times more time than compiling the project I'm interested in. Changing the structure of the solution or using assembly references are not good options for me. – Sylvain Aug 27 '10 at 20:25
  • That's not what I see here on my machine. If a run msbuild on my project, it take about 30 sec do figure out that there is nothing to do. If I do it again immediately, it takes another 30 seconds. It's process of checking the dependencies that takes time. That's why I want to skip that part. – Sylvain Aug 27 '10 at 20:35
  • 1
    I am surprised the perf is that bad. You may want to turn on MSBuild diagnostics to figure out what is taking so long. Up-to-date checking should be fast, especially if things are indeed up to date. Tools\Options\Projects&Solutions\Build&Run change MSBuild output verbosity to 'diagnostic', do your 30s action, and watch the output window during (and scour afterward) to find the 'slow' operation. – Brian Aug 27 '10 at 20:53
  • I'll check that. By the way, my PC is an Intel i7 with 6GB and a fast hard drive so I don't think it's the hardware. – Sylvain Aug 27 '10 at 20:57
1

Perhaps you could use the Configuration Manager in Visual Studio, and uncheck all the projects but the one you want to build.

grefly
  • 1,181
  • 2
  • 12
  • 28
  • I need a solution that works without changing the solution or the projets. I need this to work from the command line. – Sylvain Aug 27 '10 at 20:38
  • @Sly: Add separate configurations to your solution. You are able to select which configuration to build from the command line. This is similar to the targets in classical *make*. E.g. have a configuration *Release All*, *Debug All*, *Release Subbranch*, *Debug Subbranch*, ... – Dirk Vollmar Aug 27 '10 at 21:26
0

Check out Microsoft's best practices for structuring solutions and projects:

Microsoft Patterns & Practices: Structuring Solutions and Projects

What you currently have is a is a single solution. This is the ideal case which should be used whenever possible. However, a single solution might turn out to be impractical for very large solutions like yours.

You might want to consider to partition the solution, i.e. use separate solutions for partitions of the dependency tree. Or you might even consider to use a so-called multi-solution. Check out the linked article to see about the consequences and drawbacks of such a change. Maybe using faster hardware might be the preferable option.

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • As I wrote in my comment to grefly, I need a solution that works without changing the solution or the projets. – Sylvain Aug 27 '10 at 20:53
  • By the way, we used to have multiple solutions (for several years) but when you do that, you have to say good by to all refactoring tools and "find references" and "go to definition" and that's worst then long build times. – Sylvain Aug 27 '10 at 20:54
  • @Sly: 1.) A partitioned solution works without modifying the existing solution and projects, it just adds solutions for the sub-branches of the partition tree. 2.) Sorry, but you can't have both. For refactoring and *find references* to work all source code must be loaded, i.e. you must use project references. This is one of the reason to use a single solution whenever possible (The main reason is to have your dependencies always up-to-date and in the currect version and ready to debug). – Dirk Vollmar Aug 27 '10 at 21:01
  • 1
    I know and that's why I'm not looking for a solution that requires a redesign of my solution and projets. All I want is a "trick" to bypass this unnecessary step in some very specific scenarios. – Sylvain Aug 27 '10 at 21:07
  • @Sly: The only "trick" to tell the compiler not to check a project for modifications would be the one mentioned by @grefly, i.e. to exclude a project from build in Configuration Manager or to use a separate configuration. Probably the latter would be the best to do for you as it allows to switch you with a single-click between the configurations. – Dirk Vollmar Aug 27 '10 at 21:10
0

You should check out a product called OpenMake. My lead build engineer tells me they have done alot with dependency examination and build parallelization.

OpenMake

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100