简体   繁体   English

Visual Studio 2012不构建依赖项目

[英]Visual Studio 2012 not building dependent projects

I just upgraded a VS2010 project to VS2012 and am now having a problem where dependent projects are not building on demand. 我刚刚将VS2010项目升级到VS2012,现在遇到了一个问题,即依赖项目无法按需构建。 For instance, say I have the following projects in my solution: 例如,说我的解决方案中有以下项目:

  • Library A 图书馆A
  • ConsoleApp 1 ConsoleApp 1

Where ConsoleApp 1 references Library A. If I change the signature of a method in a class in Library A and run ConsoleApp 1, there will be a compiler error due to ConsoleApp 1 not seeing my changes because running ConsoleApp 1 did NOT cause Library A to build. ConsoleApp 1引用库A的位置。如果我在库A中的类中更改方法的签名并运行ConsoleApp 1,则会出现编译器错误,因为ConsoleApp 1看不到我的更改,因为运行ConsoleApp 1不会导致库A建立。

If I manually build Library A, then manually build ConsoleApp 1, it works fine. 如果我手动构建库A,然后手动构建ConsoleApp 1,则可以正常工作。 However, I would expect that running ConsoleApp 1 should cause any dependent projects to be rebuilt before launching. 但是,我希望运行ConsoleApp 1会导致在启动之前重建所有依赖项目。

Could I have something configured incorrectly? 我可以配置不正确吗? Or is this a bug in VS2012? 还是这是VS2012中的错误?

Your symptoms sound very similar to those I experienced a while ago . 您的症状听起来与我前一阵子非常相似。 Ensure that the projects are set to build with your current active solution configuration and active solution platform under Build->Configuration Manager . 确保在Build->Configuration Manager下将项目设置为使用当前的active解决方案configuration和活动解决方案平台进行构建。

This happens when the .suo file for the solution becomes locked and Visual Studio is no longer able to write to it. 解决方案的.suo文件被锁定并且Visual Studio不再能够写入该文件时,就会发生这种情况。 Another symptom of this problem is that you will see temp suo files being created next to the solution when you open it. 此问题的另一个症状是,打开解决方案时,您会在解决方案旁边看到正在创建的临时文件。 Try closing Visual Studio and deleting all *.suo files in your working area. 尝试关闭Visual Studio并删除工作区中的所有* .suo文件。 Then reopen Visual Studio and rebuild all. 然后重新打开Visual Studio并重新生成所有文件。 No need to manually rebuild your solution. 无需手动重建您的解决方案。 This will fix the issue when it is caused by a locked .suo, as happened to a colleague of mine today. 当我的一位同事发生这种情况时,这将解决由锁定的.suo引起的问题。

In his case, the cause seemed to be that he shutdown his laptop while Visual Studio was still open. 就他而言,原因似乎是他在Visual Studio仍处于打开状态时关闭了笔记本电脑。 Maybe the shutdown of Windows didn't complete cleanly? 也许Windows的关闭没有彻底完成? We can only speculate on how the .suo originally became locked. 我们只能推测.suo最初是如何被锁定的。

Try by removing project references and adding them again (path to follow: References -> (right click) Add reference -> Solution -> Project ). 尝试删除项目references并再次添加它们(遵循的路径: References -> (右键单击) Add reference -> Solution -> Project )。 Before giving another try Save All . 在再次尝试之前,请Save All This is how I solved it. 这就是我解决的方法。

I tried all the solutions above and that did not fix the issue for me. 我尝试了上述所有解决方案,但并没有为我解决问题。 I found that it was because of the Active configuration in the ConfigurationManager was set to build only the Main (start up) project. 我发现这是因为ConfigurationManager中的Active configuration ConfigurationManager被设置为仅构建Main(启动)项目。

Go to Build > ConfigurationManager 转到Build > ConfigurationManager

Ensure that all the projects you want to build are checked as in the screenshot below This is a similar issue on Asp.Net forum here and this is the details on MSDN . 确保所有要构建的项目进行检查,如下面的截图这是Asp.Net论坛类似的问题在这里 ,这是在细节上MSDN Although it was weired, bcoz I never changed these settings and it was working properly last week 尽管很奇怪,但是bcoz我从未更改过这些设置,并且上周工作正常 在此处输入图片说明

I've encountered a similar problem, the solution (or the probelem) were the Build and Run settings under Tools > Options... > Projects and Solutions > Build and Run where "Only build startup projects and dependencies on Run" was checked. 我遇到了类似的问题,解决(或probelem)是Build and Run下的设置Tools > Options... > Projects and Solutions > Build and Run ,其中“只有建设启动项目和依赖于运行”进行了调查。 The screenshot shows my currently working solution. 屏幕截图显示了我当前正在使用的解决方案。

Visual Studio 2012选项

For me, I resolve the issue by right clicking on the project; 对我来说,我可以通过右键单击该项目来解决此问题; Build Dependencies > Project Dependencies. 构建依赖关系>项目依赖关系。 Then manually setting the order for each project. 然后手动设置每个项目的顺序。 very painful if you have a lot of projects. 如果您有很多项目,将非常痛苦。

在此处输入图片说明

确保引用项目具有与引用项目相同或更高的.Net框架版本。

在解决方案资源管理器中右键单击解决方案,然后单击“清理解决方案”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM