I have a Visual Studio 2008 .NET C++/CLI Solution. My Solution consist of many sub projects. I define a custom buid directory for each project call it Output.
MySoultion
- 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 warning with
has already been imported from another assembly
Why i got this warnings? Does anybody has elagant solution to add same dll to multiple projects (except using GAC)
Best Wishes
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.
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.
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.
Change reference on the projects, set all "copy local ..." properties to false.
Source : http://developertips.blogspot.com/2008/07/ccli-warning-c4945.html
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!