问题描述
我发现 Visual Studio 很少有这种行为.评论之一是这可能是因为项目是从 VS2008 升级的.
I've discovered that it is rare for Visual Studio behave like this. One of the comments was this might be because the projects were upgraded from VS2008.
要具体.假设项目之间存在依赖关系,A 依赖 B,B 依赖 C,C 依赖 D.
To get specific. Say there's a dependency beween projects where A depends on B, B depends on C, and C depends on D.
A
A<--B<--C<--D.
现在假设 A 中有错误,但 B、C 和 D 编译正确.
Now say there's an error in A, but B,C,and D compiled correctly.
接下来发生的事情是,每次我尝试编译 A 时,VS 都会编译所有四个项目.
What happens next for me is that VS will compile all four projects every time I try to compile A.
命令:右击项目A,选择Build.
Command: right-click on project A, select Build.
菜单中的相同行为:Build/Build A
same behaviour from menu: Build / Build A
有没有办法确保 Visual Studio 仅在那些项目发生更改时重建依赖项目?目前 Visual Studio 会重建所有依赖项.
Is there a way to ensure that Visual Studio only rebuilds a dependent projects when there are changes in those proejcts? Currently Visual Studio rebuilds all dependencies.
我注意到下面链接上的建议是将解决方案划分为逻辑组(然后我想直接引用 .dll).如果这是最好的前进方式,是否将每个项目都构建到一个公共的 .\bin 文件夹中,然后从那里引用?
I noticed that the suggestion on the link below was to partition the solution into logical groups (and then reference .dlls directly I suppose). If this is the best way forward, is it to have each project build to a common .\bin folder, and then reference from there?
相关问题:Visual Studio 不断构建一切
如果我能保留一个大的解决方案文件就太好了.
It'd be awesome if I could keep one big solution file.
更新:
在此处描述的详细构建模式中发现了一个警告:http://support.microsoft.com/kb/2516078 不过似乎没有关系.我仍然会解决这个以防万一.(现在已修复,通过使用 $(VAR) 环境变量手动重新引用项目 + 路径提示)
discovered a warning in verbose build mode described here: http://support.microsoft.com/kb/2516078 It doesn't seem to be related though. I'm still going to fix this just-in-case. (NOW FIXED by re-referencing projects + path hints by hand using $(VAR) environment variables)
将台扇直接指向笔记本电脑.由于过热,CPU 受到限制.
pointed a desk fan directly at laptop. CPU was being throttled because of overheating.
浏览每个项目并关闭自动序列化(在项目属性/构建屏幕中找到)
went through every project and switched off auto serialization (found in the project properties / build screen)
在工具/选项/构建和运行中增加了并行构建的最大数量.我不认为这会有所帮助,因为它只是一台有两个内核的笔记本电脑,但确实如此.
increased the maximum number of parallel builds in tools / options / Build and Run. I didn't think this would help given that it is just a laptop with two cores, but it did.
看到先前已成功构建"……看起来期望的行为经常发生(仍在调查中).不过现在情况好多了.
seeing 'Previously built successfully'... so looks like desired behaviour is often occuring (still investigating). Situation is much better now though.
仍在查看详细的构建日志并整理内容.
still going through verbose build logs and tidying things up.
推荐答案
我不知道故障的原因.当我按 F5 时,VS 似乎只构建需要构建的内容.
I don't know the cause of the glitch. When I press F5, VS only seems to build what needs to be built.
但我有个建议:好好利用卸载项目"功能.如果您的解决方案仅因为您引用了它们而包含项目,但这些项目本身不依赖于您的解决方案中的任何其他内容,那么一旦它们被构建,您就可以卸载它们.
But I have a suggestion: make good use of the "Unload project" function. If your solution contains projects only because you reference them, but those projects themselves don't depend on anything else in your solution, then once they've been built you can unload them.
例如,这是我目前的情况:
For example, this is my current situation:
我正在为我的项目设计 UI.我有一个专门针对我的用户界面的解决方案.
I'm working on the UI for my project. I have a solution just for my UI.
我需要参考其他团队成员正在开发的一些库,但我自己很少对这些库进行任何更改.
I need to reference some libraries being developed by other team members, but I rarely make any changes to those libraries myself.
所以我的解决方案包含大约 15 个项目,但其中只有 10 个是我的.其他 5 个,我引用的库,不需要加载,除非我需要查看或更改该代码.所以我只是让它们卸载".
So my solution contains about 15 projects, but only 10 of them are mine. The other 5, the libraries I reference, don't need to be loaded unless I need to see or change that code. So I just keep them "unloaded".
每隔一两天我重新加载"它们,从源代码管理中获取最新更改,重新构建,然后再次卸载它们.
Every day or two I "reload" them, get latest changes from source control, rebuild, and then unload them again.
我还卸载了一些我自己很少需要更改的项目,例如我的框架库.
I also unload some of my own projects which I rarely need to change, such as my framework library.
这使我的解决方案保持敏捷,因为当我构建解决方案时,实际上只构建了大约一半的代码.它还可以加快搜索速度并使解决方案资源管理器不那么混乱.
This keeps my solution nimble because when I build the solution, only about half the code is actually built. It also speeds up searches and keeps the Solution Explorer less cluttered.
这篇关于我的解决方案中出现奇怪的 VS2010 构建故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!