加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

.net – 在同一个解决方案中为多个项目添加相同的“* .dll”引用

发布时间:2020-12-14 01:39:13 所属栏目:Windows 来源:网络整理
导读:我有一个Visual Studio 2008 .NET C/C++LI解决方案.我的解决方案包括许多子项目.我为每个项目定义一个自定义buid目录调用它的输出. MySoultion MyFirstProject(* .exe) MySecondPrject(* .dll) … MyNthProject(* .dll) 每个子项目使用Log4.net.So我创建一个
我有一个Visual Studio 2008 .NET C/C++LI解决方案.我的解决方案包括许多子项目.我为每个项目定义一个自定义buid目录调用它的输出.

MySoultion

> 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 ‘somepathlog4net.dll’: as
‘log4net::DateFormatter::AbsoluteTimeDateFormatter’
has already been imported from another assembly ‘log4net'”somepathlog4net.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
...

避免警告的方法是将Build中的Use Dependencies设置为false,以便对Proj1,Proj2,..,Projn的所有引用进行设置.

我刚刚通过演示解决方案验证了这一点,它的效果非常好 – 我无法相信解决方案有多简单,浪费了多少时间找到它!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读