简体   繁体   English

Visual Studio 2013项目参考了另一个具有外部库的项目

[英]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. 我的问题是以下问题:我在VS13中创建了不同的项目。 One of them is a project to Log (uses external library Log4net installed by NuGet). 其中一个是Log项目(使用NuGet安装的外部库Log4net)。

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. 错误29类型'log4net.ILog'是在未引用的程序集中定义的。 You must add a reference to assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'. 您必须添加对程序集'log4net,版本= 1.2.13.0,Culture =中性,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. 当使用log4net的程序集也公开log4net的类型时,通常会发生这种情况。 in that case, the consuming assembly needs reference of both the assemblies.. the one using log4net and a reference to log4net as well. 在这种情况下,使用程序集需要引用两个程序集。使用log4net的程序集以及对log4net的引用。

you need to add a reference to log4net or abstract out the types completely so that your assembly takes care of log4net types internally. 您需要添加对log4net的引用或完全抽象出类型,以便您的程序集在内部处理log4net类型。

eg If I have a project LogHelper which has 2 methods: 例如,如果我有一个具有2种方法的LogHelper项目:

Log(MyOwnLogType my) and Log(log4net.ILog log). Log(MyOwnLogType my)和Log(log4net.ILog日志)。

a caller might be using only Log(MyOwnLogType) but still the type for log4net.ILog needs to be resolved from an overall perspective. 呼叫者可能仅使用Log(MyOwnLogType),但仍使用log4net的类型。ILog需要从整体角度解决。 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. 听起来像引用log4net的项目在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. 为了引用此项目,新项目必须能够解析这些类型令牌,因此也需要引用log4net。

To fix this just use NuGet to add a reference to log4net (matching versions of course) to the new project. 要解决此问题,只需使用NuGet将对log4net(当然是匹配版本)的引用添加到新项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当将项目模板用于Visual Studio 2013时,此调试另一个项目 - When used project template for Visual Studio 2013 this debugging another project Visual Studio 2013中的项目配置 - Project configuration in Visual studio 2013 在Visual Studio中对具有不同目标平台的另一个项目的项目引用 - Project reference to another project with different target platform in Visual Studio 如何从Visual Studio 2013 Ultimate中的另一个项目导入类 - How to import a class from another project in Visual Studio 2013 Ultimate 如何将Visual Studio 2013项目降级为Visual Studio 2008项目? - How to downgrade a Visual Studio 2013 project to a Visual Studio 2008 project? Visual Studio模板上的项目参考 - Project Reference on Visual Studio Template 在Visual Studio中引用项目“readonly”? - Reference project “readonly” in Visual Studio? Visual Studio中的Azure函数 - 如何添加对另一个项目的引用 - Azure Functions in Visual Studio - How to add reference to another project 构建时,将项目的全部内容复制到另一个项目的文件夹中(Visual Studio 2013) - Copy the entire contents of a project in a folder of another project, when build (Visual Studio 2013) 在 Visual Studio 2013 中更改项目端口号 - Changing project port number in Visual Studio 2013
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM