开发者

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 act开发者_运维问答s 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.


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.


Right click on the Solution from Solution Explorer, choose Properties.

From Configuration Properties > Configuration you could exclude particular project from the build process

From Common Properties > Project Dependansies you could create and remove project dependencies

Hope this helps...

Muse Extensions


I had a similar issue with about 40 projects in one solution. For me, the following setup felt a lot less hazardous than the other answers.

  1. In Visual Studio, open up the Configuration Manager from the Build menu.
  2. Select <New...> from the Active solution configuration drop down.
  3. Enter a Name (e.g. Debug Interface) and either copy settings or create an empty configuration. You should be safe to deselect Also create new project configuration(s), especially if you only want to reduce the build time.
  4. Select or deselect the projects you want to build with your new configuration and then close the Configuration Manager.
  5. Enjoy the shorter build time using Ctrl + Shift + B or by just building the parent project. But don't forget to change to another build configuration if you want all projects to build again. Other projects that you've deselected can still be built if you right-click on them and select Build.

More information about the Configuration Manager can be found on MSDN: Configuration Manager Dialog Box.


Please review this article:

http://blogs.msdn.com/b/kirillosenkov/archive/2014/08/04/how-to-investigate-rebuilding-in-visual-studio-when-nothing-has-changed.aspx

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\General] 
"U2DCheckVerbosity"=dword:00000001 

When setting the registry key (I had to add it), just use the visual studio version that's applicable to you. E.g. 14.0 == VS2015

The diagnostic that's presented can help you determine why msbuild thinks things are out of date.


I also had this problem with C++. Dependent projects would completely recompile even when I did not change their source code or header files.

I turned off "Whole Program Optimization" for all of the dependent projects. Now my projects only rebuild if I change the source code. This option for C++ projects can be found in Properties->Configuration Properties->General.

Good Luck


I have just seen a situation like that in a solution with a couple of hundred projects. Whenever you clicked "build", VS would go and rebuild most of the projects, even if you just made a full build a second ago. Same problem if you only wanted to build a single project.

It turned out the problem was a circular dependency between projects. Normally VS does not let you create a reference from one project to another if this would cause a loop.

This only concerns "Project references", however. VS does not prevent you from adding, say ../Debug/bin/OtherSubProject.dll as a DLL reference.

Now suppose we have a solution with 100 projects, most of them, say, dependent on CoreLibrary.dll. Suppose someone adds a reference from CoreLibrary.dll to ProjectX.dll (ignoring the fact that ProjectX already depends on CoreLibrary).

If we run the build now, then first CoreLibrary.dll is built, then ProjectX.dll and all other projects.

Now suppose we run the build again, without changing anything. VS sees that one of the dependencies of CoreLibrary.dll, namely ProjectX.dll is newer than CoreLibrary.dll, and hence CoreLibrary.dll needs to be rebuilt. But of course, rebuilding the core library forces the rebuilding of all other projects, including ProjectX.dll (which will again be newer than CoreLibrary.dll).

The way to resolve this problem is to get rid of all the circular dependencies which, in particular, means that you should not reference your other subprojects via DLL references. A temporary solution while you do it would be to go to Solution Properties -> Configuration and simply disable building for one of the projects in the loop (either CoreLibrary.dll or ProjectX.dll in the example above).

There is another common reason why VS may rebuild projects which were not changed: static files with "Copy to output directory: Always" set in their properties. Avoid those.

Finally, to debug all that and figure out what is causing the rebuilds, go to Tools->Options->Projects and Solutions->Build and Run, and enable "Diagnostic" output for MSBuild. Then search for the words "not up to date" in the output window while the solution builds.


Alt + B, U will build just your current project. Good shortcut if you don't want build all projects in solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜