添加相同的“*.dll”引用同一解决方案中的多个项目
我有一个 Visual Studio 2008 .NET C++/CLI 解决方案。我的解决方案由许多子项目组成。我为每个项目定义了一个自定义构建目录,并将其称为“输出”。
我的解决方案:
- MyFirstProject (*.exe)
- MySecondPrject (*.dll)
- ...
- MyNthProject (*.dll)
每个子项目都使用 Log4.net。所以我创建一个目录(称为 LogBinary)并将 log4.net DLL 放入那个文件夹。然后,为了使用 log4net,我添加此 DLL 作为对每个项目的引用。
但是当我尝试编译我的主项目 (*.exe) 时,我收到了大量警告(超过 400 个)。
举个例子:
警告 110 警告 C4945:“AbsoluteTimeDateFormatter”: 无法从'somepath\log4net.dll'导入符号:as 'log4net::DateFormatter::AbsoluteTimeDateFormatter' 已从另一个程序集导入 'log4net'"somepath\log4net.dll"
很多警告:
已从另一个程序集导入
为什么我会收到这些警告?有没有人有解决方案将相同的 DLL 添加到多个项目(除了使用 GAC)?
I have a Visual Studio 2008 .NET C++/CLI Solution. My solution consists of many sub projects. I define a custom build directory for each project and called it "Output".
My solution:
- MyFirstProject (*.exe)
- MySecondPrject (*.dll)
- ...
- MyNthProject (*.dll)
Each of the sub project use Log4.net.So I create a directory (called LogBinary) and put log4.net DLL in that folder. Then to use log4net I add this DLL as a reference to each of my project.
But when I try to compile my main project (*.exe) I got tons of warning (over 400).
Just an example:
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"
Lots of warnings with:
has already been imported from another assembly
Why do I get these warnings? Does anybody have a solution to add same DLL to multiple projects (except using GAC)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我终于找到了解决这个问题的方法,感觉不像黑客。我在来自'的回复中找到了答案msdn 社交网站上的pyro_serv`:
因此,对于 OP 的示例,如下所示:
避免警告的方法是将所有对 Proj1、Proj2、..、Projn 的引用设置为 false。 。
我刚刚用一个演示解决方案验证了这一点,它运行得很好 - 我不敢相信这个解决方案是如此简单以及我浪费了多少时间来找到它!
I finally found a solution to this problem which doesn't feel like a hack. I found the answer in a response from 'pyro_serv` on the msdn social site:
So for the OP's example which looks something like this:
The way to avoid the warnings is to set
Use Dependencies in Build
to false for all of the references toProj1,Proj2,..,Projn
.I've just verified this with a demo solution and it works great - I can't believe how simple the solution is and how much time I've wasted to find it!
更改项目上的引用,将所有“复制本地...”属性设置为 false。
来源:http://developertips.blogspot.com/2008/07/ccli -警告-c4945.html
Change reference on the projects, set all "copy local ..." properties to false.
Source : http://developertips.blogspot.com/2008/07/ccli-warning-c4945.html
我今天又遇到同样的问题。
首先,感谢乔恩·凯奇(Jon Cage)和他在该线程上的帖子中的链接文章,参见上面(或下面)。 +1!!!它解决了我的问题。
但是因为我讨厌诸如
根据您的情况切换它们
之类的事情,这意味着除了反复试验
之外什么也没有,所以我做了一些测试,因为我有 2 个解决方案,其中有很多每个中都有 C++/CLI 项目。这是我的建议和解释:
对于所有“自行创建”的程序集(将“复制本地”设置为 true):
通过取消选中此参数
Use Dependencies In Build
设置为“false”。它充当“参考转发”,请参见下面的示例。
技术背景:
->意思是“参考文献”
方法一:
在我的解决方案 SwCore 中:
A.1.1
网络->工具
,A.1.2网络->基础
。A.2.1
工具->基础
。A.3.1
驱动器->基础知识
、A.3.2驱动器->工具
、A.3.3驱动器->网络
A.4.1 ...
将“在构建中使用依赖项”设置为 true 时,可以省略引用 A.1.2,因为它包含在 A.2.1 中。
所有文件均在 swcore\release\
中创建
==问题:
在解决方案 DDI 中:
B.1.1
DDI_hardware->DDI_job
、B.1.2DDI_hardware->drives
B.2.1
DDI_job->基础知识
、B.2.2DDI_job->工具
、B.2.3 DDI_job->作业
DDI_job
在 DDI\Release\ 中创建,并将“UDInBuild”设置为 true,其中包含基础知识
。DDI_hardware
已创建...并且“UDInBuild”设置为 true,它包括DDI_job->basics
。DDI_hardware 还参考了 SwCore\Release\
的基础知识
==>>双重参考基础知识和其他知识。 VS看到2个文件,无法识别出是相同的内容。
方法2:
A.1.1
网络->工具
,A.1.2网络->基础
。A.2.1
工具->基础
。当“UDInBuild”设置为 FALSE 时,不能省略引用 A.1.2,因为它不是从 A.2.1 转发的。
== 有效,因为任何程序集都不会包含其他更深层次的依赖项,因此不会发生冲突。
顺便说一句:这会强制您为每个项目指定所有必要的引用,因此您还可以了解您要做什么在你的项目中使用。
最后信息:我不能确定我的解释是否正确。也许其他可以确认。
I had the same problem again today.
First of all, thanks to Jon Cage and the linked article in his post on this thread, see above (or below). +1!!! It solved my problem.
But because I hate things like
toggle them as appropriate for your case
, which means nothing buttrial and error
, I did some tests as I have 2 solutions with a good number of C++/CLI projects in each.Here's my advice and explanation for it:
For all 'self created' assemblies (that have 'copy local' set to true):
Set this parameter
Use Dependencies In Build
to "false" by unchecking.It works as 'reference forwarding', see example below.
TECHNICAL BACKGROUND:
-> means 'references'
method 1:
in my solution SwCore:
A.1.1
network->tools
, A.1.2network->basics
.A.2.1
tools->basics
.A.3.1
drives->basics
, A.3.2drives->tools
, A.3.3drives->network
A.4.1 ...
with "Use Dependencies In Build" set to true, the reference A.1.2 can be omitted, as it is included in A.2.1.
all files are created in swcore\release\
== problem:
in solution DDI:
B.1.1
DDI_hardware->DDI_job
, B.1.2DDI_hardware->drives
B.2.1
DDI_job->basics
, B.2.2DDI_job->tools
,B.2.3 DDI_job->job
DDI_job
is created in DDI\Release\ and with "U.D.InBuild" set to true, it includesbasics
.DDI_hardware
is created... and with "U.D.InBuild" set to true, it includesDDI_job->basics
.DDI_hardware also references basics from SwCore\Release\
==>> double reference to basics and others. VS sees 2 files and can not realize that it is the same content.
method 2:
A.1.1
network->tools
, A.1.2network->basics
.A.2.1
tools->basics
.with "U.D.InBuild" set to FALSE, the reference A.1.2 can NOT be omitted, because it is not forwarded from A.2.1.
== works, because no assembly will contain other deeper dependencies, so there won't be conflicts.
BTW: This forces you to specifiy all necessary references for each project, so you also have an overview what you are using in your project.
Last info: I can not tell for sure, if my explanation is correct. Maybe s.o. else can confirm.
我遇到了同样的问题。
这是由以下情况引起的,其中一个项目依赖于另一个项目:
当我删除对 System.dll 的引用(例如)时,它解决了编译器警告。
I had this exact same problem.
It is caused by the following situation, where a project depends on another project:
When I removed the reference to System.dll (for instance) it solved the compiler warning.
我对这种情况有同样的警告:
依赖关系如下。
将 Project2 Outdir 修复为“C:\out”(正如实际预期,它是一个新创建的项目,忘记更改它)修复了警告。
I had the same warning on this situation:
The dependencies relations were the following ones.
Fixing Project2 Outdir to "C:\out" (as actually intended, it was a newly created project and forgot to change it) fixed the warning.