引用的项目在编译时“丢失”

我有一个包含两个项目的 C # 解决方案: 一个服务(主项目)和一个日志记录器。服务使用日志记录器中的类。我已经在服务项目中添加了对日志记录器项目的引用。在设计时,自动完成工作良好: 日志记录器的类是可见的,我使用的引用被适当地着色。

我重新构建解决方案,结果出了问题。引用不再被识别: “名称‘ Logging’在当前上下文中不存在”,类在自动完成中不再存在。删除并重新附加引用使我回到基本状态,即标识符可以自动完成。

我已经重新启动,清除所有缓存,确保这是唯一的实例 VS 2010运行在我的机器上。

我是不是漏掉了什么显而易见的东西?

149538 次浏览

Check your build types of each project under project properties - I bet one or the other will be set to build against .NET XX - Client Profile.

With inconsistent versions, specifically with one being Client Profile and the other not, then it works at design time but fails at compile time. A real gotcha.

There is something funny going on in Visual Studio 2010 for me, which keeps setting projects seemingly randomly to Client Profile, sometimes when I create a project, and sometimes a few days later. Probably some keyboard shortcut I'm accidentally hitting...

Make sure that both projects have same target framework version here: right click on project -> properties -> application (tab) -> target framework

Also, make sure that the project "logger" (which you want to include in the main project) has the output type "Class Library" in: right click on project -> properties -> application (tab) -> output type

Finally, Rebuild the solution.