c# - Visual Studio 2010 程序集引用问题

标签 c# visual-studio-2010 assemblies

我正在使用 Visual Studio 2010 和 C# 来构建 WinForms 应用程序和类库。我有一些用于所有产品的通用库,还有一些用于我的应用程序的产品特定库。我的程序集均未经过 GAC 认证。所有项目都将其输出从各自的 bin\Debug 文件夹复制到公共(public)存储库文件夹,并且所有程序集引用都指向该存储库文件夹。

例如,Common.DAL.dll、Common.BLL.dll、Product.DAL.dll、Product.BLL 和 Product.exe

程序集之间的引用通常如下所示:

  • Product.exe 包含对 Product.BLL 的引用
  • Product.BLL 包含对 Common.BLL 和 Product.DAL 的引用
  • Product.DAL 包含对 Common.DAL 的引用
  • Common.BLL 包含对 Common.DAL 的引用

当所有这些都包含在同一个解决方案中时,构建依赖关系如下所示:

  • Common.BLL 依赖于 Common.DAL
  • Product.DAL 依赖于 Common.DAL
  • Product.BLL 取决于 Common.BLL 和 Product.DAL
  • Product.exe 依赖于 Product.BLL

这使得构建顺序如下:

  1. Common.DAL
  2. Common.BLL
  3. 产品.DAL
  4. 产品.BLL
  5. 产品.exe

尝试运行应用程序时,我经常会收到以下错误:

无法加载文件或程序集“Common.DAL,Version=1.0.0.0,Culture=neutral,PublicKeyToken=4e5249f2e70e1da8”或其依赖项之一。系统找不到指定的文件。

我已将问题追溯到以下事实:并非所有从解决方案构建的程序集最终都位于 Product.exe 的 bin\Debug 文件夹中。

如果我清理解决方案,然后重建它,文件将显示如下:

  • Common.DAL\bin\Debug 包含 Common.DAL.dll
  • Common.BLL\bin\Debug 包含 Common.BLL.dll 和 Common.DAL.dll
  • Product.DAL\bin\Debug 包含 Common.DAL.dll 和 Product.DAL.dll
  • Product.BLL\bin\Debug 包含 Common.BLL.dll、Common.DAL.dll、 Product.BLL.dll 和 Product.DAL.dll
  • 但 Product.exe\bin\Debug 仅包含 Product.exe、Product.BLL 和 产品.DAL。 它缺少通用程序集。所以当我运行时 Product.exe,我收到上面列出的错误。

我已经检查了我的所有项目和属性的属性。它们都使用 .NET Framework 4。对我的程序集的所有引用都将“特定版本”属性设置为 false,并将“复制本地”属性设置为 true。

我可以通过在 Product.exe 项目中添加对通用程序集的引用来强制将缺少的程序集复制到 Product.exe\bin\Debug,但由于 Product.exe 不会< em>显式使用通用程序集,这感觉更像是一个拼凑而不是解决方案。

我浏览了 MSDN 和 Visual Studio 文档,看看是否可以找出影响或影响引用程序集的复制的因素,并且我已经搜索了类似的问题,但没有发现任何有用的内容。

我不知道该去哪里或下一步该做什么。

最佳答案

在你的问题中你说:

I can force the missing assemblies to be copied to Product.exe\bin\Debug by adding references to the Common assemblies in the Product.exe project, but since Product.exe doesn't explicitly use the Common assemblies, this feels more like a kludge than a solution.

我想我不同意。它并不完美,但 Visual Studio 有时甚至需要这种内部解决方案。这取决于您如何使用该类。

虽然您可能认为这有点困惑,但似乎您的其他(我敢说“困惑”)需求(每个解决方案一个项目)使事情看起来很困惑

关于c# - Visual Studio 2010 程序集引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8070247/

相关文章:

.net - 将生成操作更改为发布而不是调试后控制丢失

用于 visual studio 的 C# 解释器插件

c# - 程序集:InternalsVisibleTo attribute?的 "AllInternalsVisible"参数是什么

c# - 我怎样才能抛出带有特定 HResult 的异常?

java - 在 Java Android 中加密并在 C# Unity 中解密

c# - 如何使用 C# 在未安装 Microsoft Office 的情况下将 .xls 文件转换为 .xlsx?

c# - .NET 将类解析为错误的 DLL

asp.net - 目标平台和 'Could not load file or assembly'错误

web-applications - 在 Web 应用程序的页脚中显示底层软件的版本?

c# - C# 中的线程和 lambda