views:

2333

answers:

13

I have a C# project which includes one exe and 11 library files. The exe references all the libraries, and lib1 may reference lib2, lib3, lib4, etc.

If I make a change to a class in lib1 and built the solution, I assumed that only lib1 and the exe would need to be changed. However, all dll's and the exe are being built if I want to run the solution.

Is there a way that I can stop the dependencies from being built if they have not been changed?

+2  A: 
CMS
I would still like the project to build if it has changed. This will not build the project if it has changed. Thanks though!
Brad Leach
+4  A: 

I am not sure if there is a way to avoid dependencies from being built. You can find some info here like setting copylocal to false and putting the dlls in a common directory.

Optimizing Visual Studio solution build - where to put DLL files?

Gulzar
A: 

I don't think there's away for you to do it out of the box in VS. You need this add-in http://workspacewhiz.com/

It's not free but you can evaluate it before you buy.

volatilsis
A: 

Yes, exclude the non-changing bits from the solution. I say this with a caveat, as you can compile in a way where a change in build number for the changed lib can cause the non built pieces to break. This should not be the case, as long as you do not break interface, but it is quite common because most devs do not understand interface in the .NET world. It comes from not having to write IDL. :-)

As for X projcts in a solution, NO, you can't stop them from building, as the system sees a dependency has changed.

BTW, you should look at your project and figure out why your UI project (assume it is UI) references the same library as everything else. A good Dependency Model will show the class(es) that should be broken out as data objects or domain objects (I have made an assumption that the common dependency is some sort of data object or domain object, of course, but that is quite common). If the common dependency is not a domain/data object, then I would rethink my architecture in most cases. In general, you should be able to create a path from UI to data without common dependencies other than non-behavioral objects.

Gregory A Beamer
+2  A: 

Now, after I say this, some propeller-head is going to come along and contradict me, but there is no way to do what you want to do from Visual Studio. There is a way of doing it outside of VS, but first, I have a question:

Why on earth would you want to do this? Maybe you're trying to save CPU cycles, or save compile time, but if you do what you're suggesting you will suddenly find yourself in a marvelous position to shoot yourself in the foot. If you have a library 1 that depends upon library 2, and only library 2 changes, you may think you're OK to only build the changed library, but one of these days you are going to make a change to library 2 that will break library 1, and without a build of library 2 you will not catch it in the compilation. So in my humble opinion, DON'T DO IT.

The reason this won't work in VS2005 and 2008 is because VS uses MSBuild. MSBuild runs against project files, and it will examine the project's references and build all referenced projects first, if their source has changed, before building the target project. You can test this yourself by running MSBuild from the command line against one project that has not changed but with a referenced project that has changed. Example:

msbuild ClassLibrary4.csproj

where ClassLibrary4 has not changed, but it references ClassLibrary5, which has changed. MSBuild will build lib 5 first, before it builds 4, even though you didn't mention 5.

The only way to get around all these failsafes is to use the compiler directly instead of going through MSBuild. Ugly, ugly, but that's it. You will basically be reduced to re-implementing MSBuild in some form in order to do what you want to do.

It isn't worth it.

Cyberherbalist
From you example, I have no problem for the build system to build "library 1" if "library 2" changes. I do have issue with changing "library 1" and the build system automatically builds "library 2" (even though library 2 and any of its dependencies haven't changed).
Brad Leach
Are you sure you're not clicking on Rebuild instead of Build? I do not get the behavior you're reporting. When I mod library 1, the system does not build library 2 if there have been no changes. Rebuild builds everything regardless, but Build should not.
Cyberherbalist
I am experiencing the same problem as Brad Leach and so is the rest of my development team.. The only solution we found which works is to build with a platform specific configuration.
RobS
+22  A: 

Is the key this phrase? "However, all dll's and the exe are being built if I want to run the solution"

Visual Studio will always try to build everything when you run a single project, even if that project doesn't depend on everything. This choice can be changed, however. Go to Tools|Options|Projects and Solutions|Build and Run and check the box "Only build startup projects and dependencies on Run". Then when you hit F5, VS will only build your startup project and the DLLs it depends on.

Sebastian Good
It doesn't seem to have any effect when you Build the solution though (i.e. Ctrl + Shift + B) - it still compiles unchanged projects.
RobS
+1 You just shaved 5 minutes off my code-test turn around time :)
Dead account
Rob -- It will always scan projects to see if they have changed, and put output into the build indicating it has done so, but it should not be recompiling them. If it is, you may want to check your pre- or post- build tasks elsewhere to be sure they are not triggering changes in your dependencies.
Sebastian Good
+3  A: 
RobS
+3  A: 

We had a similar problem at work. In post-build events we were manually embedding manifests into the outputs in the bin directory. Visual Studio was copying project references from the obj dir (which weren't modified). The timestamp difference triggered unnecessary rebuilds.

If your post-build events modify project outputs then either modify the outputs in the bin and obj dir OR copy the modified outputs in the bin dir on top of those in the obj dir.

Arnshea
A: 

Not sure of an awesome way to handle this, but in the past if I had a project or two that kept getting rebuilt, and assuming I wouldn't be working in them, I would turn the build process off for them.

Right click on the sln, select configuration manager and uncheck the check boxes. Not perfect, but works when Visual Studio isn't behaving.

Mallioch
+1  A: 

Check out the following site for more detailed information on when a project is built as well as the differences between build and rebuild.

Chris Lively
I concur with Chris. If you say "rebuild" you mean "rebuild this even if it doesn't seem to need it". If you "build", then already built projects will be skipped.
MatthewMartin
The problem is that "build" is acting like "rebuild". I've also seen this behavior on other projects.
From the site you linked to:" Anonymous said... Glad I found this article. I just installed new VS8, and when I select Build, it always rebuilds all of my projects, even if nothing has changed. Anyone have any idea what to look at?? Same sln/projects do not do this running in .NET [email protected]"THIS is what I'm experiencing!!Your statemtment, "If you "build", then already built projects will be skipped.", while theoretically true, is incorrect in these cases.
We have been struggling with build 'building' up to date projects as well. Both 2005 and 2008.
KJAWolf
A: 

I had this problem too, and noticed these warning messages when building on Windows 7 x64, VS2008 SP1:

cl : Command line warning D9038 : /ZI is not supported on this platform; enabling /Zi instead

cl : Command line warning D9007 : '/Gm' requires '/Zi'; option ignored

I changed my project properties to:

C/C++ -> General -> Debug Information Format = /Zi

C/C++ -> Code Generation -> Enable Minimal Build = No

After rebuilding I switched them both back and dependencies work fine again. But prior to that no amount of cleaning, rebuilding, or completely deleting the output directory would fix it.

Nathan Kidd
2010-06-23 - It happened again and flipping the /Zi switch was enough to fix it. Cleaning output, deleting all generated files (.ncb, etc.) wasn't enough. It isn't a matter of from-the-future files either.
Nathan Kidd
A: 

I just "fixed" the same problem with my VS project. Visual Studio did always a rebuild, even if didn't change anything. My Solution: One cs-File had a future timestamp (Year 2015, this was my fault). I opened the file, saved it and my problem was solved!!!

HBdieRE
A: 

If no real reason (like loops of building dependencies or other ugly stuff that shouldn't really exist) Restarting the studio usually fixes it.

Simple as that.

Veltz