简体   繁体   中英

Visual studio 2013 project reference another project with external libraries

I have a problem and don't know what are the best steps to do.

My problem is the following one: I have created different projects in VS13. One of them is a project to Log (uses external library Log4net installed by NuGet).

Now I want to use that project in the other projects...but everytime I reference the project I get the following error:

Error 29 The type 'log4net.ILog' is defined in an assembly that is not referenced. You must add a reference to assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.

Any idea how can I solve this?

Thanks in advance.

This normally happens when the assembly using log4net also exposes types from log4net. in that case, the consuming assembly needs reference of both the assemblies.. the one using log4net and a reference to log4net as well.

you need to add a reference to log4net or abstract out the types completely so that your assembly takes care of log4net types internally.

eg If I have a project LogHelper which has 2 methods:

Log(MyOwnLogType my) and Log(log4net.ILog log).

a caller might be using only Log(MyOwnLogType) but still the type for log4net.ILog needs to be resolved from an overall perspective. So please ensure if any such type is leaking through your helper assembly into the callers.

It sounds like the the project which references log4net exposes one of its types in a public / internal API. In order to reference this project the new project must be able to resolve these type tokens and hence needs a reference to log4net as well.

To fix this just use NuGet to add a reference to log4net (matching versions of course) to the new project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM