简体   繁体   English

Visual Studio 2010中的参考项目与参考DLL

[英]Reference Project vs Reference DLL in Visual Studio 2010

I am running into a very strange problem and I would like to understand what is happening. 我遇到了一个非常奇怪的问题,我想了解发生了什么。 I have a solution with 30 projects and all it is working fine except one of them. 我有一个包含30个项目的解决方案,除了其中一个项目之外它一切正常。 This project has a dependency on another project in the same solution. 该项目依赖于同一解决方案中的另一个项目。 Adding a Project reference, looks fine in the editor (no red lines etc) but when compiling I get compiler error as if the reference is not there. 添加一个Project引用,在编辑器中看起来很好(没有红线等)但是在编译时我得到了编译器错误,好像引用不存在一样。 However if I go and Add Reference directly on the DLL which the project generates then it works fine. 但是,如果我直接在项目生成的DLL上添加引用,那么它可以正常工作。 I double check and in both scenarios it references the exact same DLL. 我仔细检查,并在两种情况下它引用完全相同的DLL。 Why it wouldn't work as a project reference? 为什么它不能作为项目参考? Any ideas welcome ! 欢迎任何想法!

Project build order is a ratty problem to solve and MSBuild certainly does drop the ball sometimes. 项目构建顺序是一个很难解决的问题,而MSBuild肯定会丢球。 There isn't anything in the question that helps us help you find the root cause. 问题中没有任何内容可以帮助我们找到根本原因。

The simple solution is to help MSBuild and just be explicit about it. 简单的解决方案是帮助MSBuild并明确它。 Right-click the project that doesn't build correctly and select "Project Dependencies". 右键单击未正确构建的项目,然后选择“项目依赖项”。 Tick the ones that need to built first. 勾选需要先建立的那些。 Also note the Build Order tab in that same dialog, it shows you in what order the projects are going to get built. 另请注意同一对话框中的Build Order选项卡,它会显示项目的构建顺序。 Make sure it is now a happy order. 确保它现在是一个快乐的订单。

Also note that it is technically possible to create a circular dependency. 另请注意,在技术上可以创建循环依赖项。 It isn't simple to do, it requires incrementally changing the projects and adding references to existing DLLs. 这并不简单,它需要逐步更改项目并添加对现有DLL的引用。 In other words, what you did and shouldn't have done :) You diagnose that with Build + Clean and never succeeding in building the solution again. 换句话说,你做了什么,不应该做什么:)你用Build + Clean诊断它,并且再也没有成功构建解决方案。

When I've run into issues like this I've generally fixed them by one of two things... 当我遇到这样的问题时,我通常会用两件事中的一件来修复它们......

  1. Close VS and re-open the solution. 关闭VS并重新打开解决方案。 It sometimes "get's confused" about references 它有时会对引用“感到困惑”
  2. Remove project references and re-add 删除项目引用并重新添加

You might not be referencing the latest build of the said DLL. 您可能没有引用所述DLL的最新版本。 The direct DLL reference will not force that DLL to be rebuilt, but a project reference will. 直接DLL引用不会强制重建该DLL,但项目引用将会。 Sometimes VS does not report dependency DLL build errors clearly, so it could well be that there is an error in the latest code for the DLL and one you are linking to is an old one. 有时VS不会清楚地报告依赖DLL构建错误,因此很可能是DLL的最新代码中存在错误,而您链接的代码是旧错误。 Try looking at the output window (as opposed to the errors list) for detail on why it won't build. 尝试查看输出窗口(而不是错误列表),详细了解它不会构建的原因。

I'll recommend editing the project file and taking a look at what each reference is actually pointing at. 我建议编辑项目文件并查看每个引用实际指向的内容。 Also, check the configuration manager and make sure that the 'problem' project is being included when being build for the particular platform \\ configuration you are building against. 此外,检查配置管理器并确保在为您构建的特定平台\\配置构建时包含“问题”项目。 '

Both projects are in the same solution? 这两个项目都在同一个解决方案中? If yes, you might want to check the build order for them, make sure the referenced one is build before the one that references it. 如果是,您可能需要检查它们的构建顺序,确保引用它的构建顺序在引用它之前构建。 Also there is a bug in the MSBuild maybe this will solve your problem : solution to MSBuild error 此外,MSBuild中还有一个错误,这可能会解决您的问题: 解决MSBuild错误

The name of the project was different from the name of the folder was under. 项目的名称与文件夹的名称不同。 Not sure it had something to do with that when using it as project reference but renaming the project folder fixed the issue. 当使用它作为项目参考时,不确定它与此有关,但重命名项目文件夹修复了问题。

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

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