Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop Visual Studio from building dependencies that have not changed?

The title is fairly straightforward. If I hit the build button, it acts like the "Rebuild All" button. If I have two projects, lets call them PARENT and CHILD, and I make a change to Parent and click the "Build" button. The default behavior in VS is to rebuild PARENT AND CHILD, when it should only rebuild PARENT.

I was wondering if this is an option in Visual Studio and how I can change it.

Thanks.

like image 721
stringa Avatar asked May 04 '11 19:05

stringa


People also ask

How do I stop an ongoing build in Visual Studio?

You can hit Ctrl + Break on the keyboard to cancel/stop a build that is currently in progress.

How do I clean up and build in Visual Studio?

To build, rebuild, or clean an entire solutionChoose Build All to compile the files and components within the project that have changed since the most recent build. Choose Rebuild All to "clean" the solution and then builds all project files and components. Choose Clean All to delete any intermediate and output files.


1 Answers

There seems to be some inconsistencies in your question, so I'm going to define the terms I'm using, for clarity.

  • Build: Compile & link everything required for the application/project
  • Clean: Delete all files produced as part of a build.
  • Rebuild: Perform a clean, then a build.

My Visual Studio doesn't have a '(Re)build All' button, it does however have a '(Re)build Solution' button, so I'm going to assume you mean that. I'm also going to assume that where you've said rebuild PARENT and CHILD, you meant build PARENT and CHILD, and that it's not recompiling each and every file in the project.

The Build and Build Solution options are not the same.

  • Performing a Build will evaluate the current project (and its dependencies), compiling anything required.
  • Performing a Build Solution will evaluate all projects in the solution, compiling anything required.

So, if you have a solution with 3 projects:

  1. Child
  2. Service (Dependent on Child)
  3. FrontEnd

Then, assuming the currently selected project is Service:

  • Build: Would evaluate/compile: Child & Service
  • Build Solution: Would evaluate/compile: Child, Service & FrontEnd

Now, I believe what you are seeing is that when you perform a build on Parent, VS is performing a build on Child as well, even though it hasn't changed. I would expect that it is evaluating Child, because it needs to know if it has changed. Without performing the evaluation, there's no way it can know, which is why in your output window you'll see that it has done something with the Child project. This is usually fairly quick, although it does add up if you have a lot of dependencies.

If you don't want VS to evaluate your dependencies when you build the parent, then there are approaches you can follow but you're choosing to step away from the tools protection so unless you're careful you may get binary mismatches etc...

Some options:

  • Unload child projects that you're not changing (right click in solution explorer and select unload). This hides the dependency so it doesn't get compiled).
  • Stop letting visual studio manage your dependencies. The safest way to do this is to remove the Project Based references and instead use Binary Based references (point at the compiled output from each dependency). But this can be a non-trivial undertaking, since you have to manage your project builds yourself.

I'd suggest you think twice about what it is you're asking and evaluate whether or not the time saving (there can be some) is worth the risk that now and again you might not build everything you needed to and so end up spending time chasing your tail.

like image 121
forsvarir Avatar answered Sep 21 '22 22:09

forsvarir