.net - 向同一解决方案中的多个项目添加相同的 "*.dll"引用

标签 .net dll log4net gac

我有一个 Visual Studio 2008 .NET C++/CLI 解决方案。我的解决方案由许多子项目组成。我为每个项目定义了一个自定义构建目录,并将其称为“输出”。

我的解决方案:

  • MyFirstProject (*.exe)
  • MySecondPrject (*.dll)
  • ...
  • MyNthProject (*.dll)

  • 每个子项目都使用 Log4.net.So 我创建一个目录(称为 LogBinary)并将 log4.net DLL 放在该文件夹中。然后为了使用 log4net,我添加了这个 DLL 作为对我的每个项目的引用。

    但是当我尝试编译我的主项目 (*.exe) 时,我收到了大量警告(超过 400 个)。

    只是一个例子:

    Warning 110 warning C4945: 'AbsoluteTimeDateFormatter' : cannot import symbol from 'somepath\log4net.dll': as 'log4net::DateFormatter::AbsoluteTimeDateFormatter' has already been imported from another assembly 'log4net'"somepath\log4net.dll"



    很多警告:

    has already been imported from another assembly



    为什么我会收到这些警告?有没有人有将相同的 DLL 添加到多个项目的解决方案(使用 GAC 除外)?

    最佳答案

    我终于找到了解决这个问题的方法,这不像是一个黑客。我在 a response from 'pyro_serv` on the msdn social site 中找到了答案:

    The fix is to use the "Use Dependencies In Build" and "Use In Build" flags on each VC project references (via the VC properties sheet), and toggle them as appropriate for your case to resolve this error.



    所以对于 OP 的例子,它看起来像这样:
    Solution -> Log4.net
    Solution -> Proj1
    Solution -> Proj1 -> Log4.net
    Solution -> Proj2
    Solution -> Proj2 -> Log4.net
    ...
    

    避免警告的方法是设置 Use Dependencies in Build为所有对 Proj1,Proj2,..,Projn 的引用设置为 false .

    我刚刚用一个演示解决方案验证了这一点,它运行得很好 - 我不敢相信这个解决方案是多么简单,我浪费了多少时间来找到它!

    关于.net - 向同一解决方案中的多个项目添加相同的 "*.dll"引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4692155/

    相关文章:

    c - 如何使用 .exe 文件传送 .dll 文件

    c# - 在 C# 应用程序中调用 C++ DLL 函数时如何修复从上下文加载错误

    c# - Log4Net 的隐藏 gem ?

    .net - Linq to NHibernate

    c# - 装箱/拆箱可空类型 - 为什么要执行此操作?

    c# - 有人使用 CLI 后端为 gcc 编译器编译 lib x264 吗?

    c# - 创建一个新的 AnonymousType 实例

    c++ - 导出数据成员是否正确? (C++)

    c# - 如何删除旧的 log4net 日志文件?

    caSTLe-windsor - MassTransit 2.6.1 请求/响应模式 - 响应超时