警告:发现同一依赖程序集的不同版本之间存在冲突

本文翻译自:Warning: Found conflicts between different versions of the same dependent assembly

I am currently developing a .NET application, which consists of 20 projects. 我目前正在开发一个.NET应用程序,它包含20个项目。 Some of those projects are compiled using .NET 3.5, some others are still .NET 2.0 projects (so far no problem). 其中一些项目是使用.NET 3.5编译的,其他一些项目仍然是.NET 2.0项目(到目前为止没问题)。

The problem is that if I include an external component I always get the following warning: 问题是,如果我包含一个外部组件,我总会得到以下警告:

"Found conflicts between different versions of the same dependent assembly".

What exactly does this warning mean and is there maybe a possibility to exclude this warning (like using #pragma disable in the source- code files)? 这个警告究竟是什么意思,是否有可能排除这个警告(比如在源代码文件中使用#pragma disable)?


#1楼

参考:https://stackoom.com/question/4dC/警告-发现同一依赖程序集的不同版本之间存在冲突


#2楼

I had the same problem with one of my projects, however, none of the above helped to solve the warning. 我的一个项目遇到了同样的问题,但是,上述任何一个都没有帮助解决警告。 I checked the detailed build logfile, I used AsmSpy to verify that I used the correct versions for each project in the affected solution, I double checked the actual entries in each project file - nothing helped. 我检查了详细的构建日志文件,我使用AsmSpy来验证我在受影响的解决方案中为每个项目使用了正确的版本,我仔细检查了每个项目文件中的实际条目 - 没有任何帮助。

Eventually it turned out that the problem was a nested dependency of one of the references I had in one project. 最终它发现问题是我在一个项目中的一个引用的嵌套依赖项。 This reference (A) in turn required a different version of (B) which was referenced directly from all other projects in my solution. 该引用(A)又需要不同版本的(B),它直接从我的解决方案中的所有其他项目引用。 Updating the reference in the referenced project solved it. 更新引用项目中的引用解决了它。

Solution A
+--Project A
   +--Reference A (version 1.1.0.0)
   +--Reference B
+--Project B
   +--Reference A (version 1.1.0.0)
   +--Reference B
   +--Reference C
+--Project C
   +--Reference X (this indirectly references Reference A, but with e.g. version 1.1.1.0)

Solution B
+--Project A
   +--Reference A (version 1.1.1.0)

I hope the above shows what I mean, took my a couple of hours to find out, so hopefully someone else will benefit as well. 我希望以上显示我的意思,花了几个小时才发现,所以希望其他人也会受益。


#3楼

Basically this happens when the assemblies you're referencing have "Copy Local" set to "True", meaning that a copy of the DLL is placed in the bin folder along with your exe. 基本上,当您引用的程序集将“Copy Local”设置为“True”时会发生这种情况,这意味着DLL的副本与您的exe一起放在bin文件夹中。

Since Visual Studio will copy all of the dependencies of a referenced assembly as well, it's possible to end up with two different builds of the same assembly being referred to. 由于Visual Studio也会复制引用程序集的所有依赖项,因此最终可能会引用同一程序集的两个不同构建。 This is more likely to happen if your projects are in separate solutions, and can therefore be compiled separately. 如果您的项目位于单独的解决方案中,则更有可能发生这种情况,因此可以单独编译。

The way I've gotten around it is to set Copy Local to False for references in assembly projects. 我得到的方法是将装配项目中的引用设置为Copy Local为False。 Only do it for executables/web applications where you need the assembly for the finished product to run. 仅对需要运行成品的程序集的可执行文件/ Web应用程序执行此操作。

Hope that makes sense! 希望有道理!


#4楼

This actually depends on your external component. 这实际上取决于您的外部组件。 When you reference an external component in a .NET application it generates a GUID to identify that component. 在.NET应用程序中引用外部组件时,它会生成GUID以标识该组件。 This error occurs when the external component referenced by one of your projects has the same name and but different version as another such component in another assembly. 当您的某个项目引用的外部组件与另一个程序集中的另一个此类组件具有相同名称但版本不同时,会发生此错误。

This sometimes happens when you use "Browse" to find references and add the wrong version of the assembly, or you have a different version of the component in your code repository as the one you installed in the local machine. 当您使用“浏览”查找引用并添加错误版本的程序集时,或者您在代码存储库中具有与本地计算机中安装的组件不同的组件版本时,有时会发生这种情况。

Do try to find which projects have these conflicts, remove the components from the reference list, then add them again making sure that you're pointing to the same file. 尝试查找哪些项目存在这些冲突,从参考列表中删除组件,然后再次添加它们,确保您指向同一文件。


#5楼

This warning means that two projects reference the same assembly (eg System.Windows.Forms ) but the two projects require different versions. 此警告意味着两个项目引用相同的程序集(例如System.Windows.Forms ),但这两个项目需要不同的版本。 You have a few options: 你有几个选择:

  1. Recompile all projects to use the same versions (eg move all to .Net 3.5). 重新编译所有项目以使用相同的版本(例如,将所有项目全部移至.Net 3.5)。 This is the preferred option because all code is running with the versions of dependencies they were compiled with. 这是首选选项,因为所有代码都使用它们编译的依赖项版本运行。

  2. Add a binding redirect . 添加绑定重定向 This will suppress the warning. 这将抑制警告。 However, your .Net 2.0 projects will (at runtime) be bound to the .Net 3.5 versions of dependent assemblies such as System.Windows.Forms . 但是,您的.Net 2.0项目将(在运行时)绑定到.Net 3.5版本的依赖程序集,如System.Windows.Forms You can quickly add a binding redirect by double-clicking on error in Visual Studio. 您可以通过双击Visual Studio中的错误来快速添加绑定重定向。

  3. Use CopyLocal=true . 使用CopyLocal=true I'm not sure if this will suppress the warning. 我不确定这是否会抑制警告。 It will, like option 2 above, mean that all projects will use the .Net 3.5 version of System.Windows.Forms. 它将像上面的选项2一样,意味着所有项目都将使用.Net 3.5版本的System.Windows.Forms。

Here are a couple of ways to identify the offending reference(s): 以下是识别违规参考的几种方法:

  • You can use a utility such as the one found at https://gist.github.com/1553265 您可以使用https://gist.github.com/1553265上的实用程序
  • Another simple method is to set Build output verbosity (Tools, Options, Projects and Solutions, Build and Run, MSBuild project build output verbosity, Detailed) and after building, search the output window for the warning, and look at the text just above it. 另一个简单的方法是设置构建输出详细程度(工具,选项,项目和解决方案,构建和运行,MSBuild项目构建输出详细程度,详细),并在构建后,在输出窗口中搜索警告,并查看其上方的文本。 (Hat tip to pauloya who suggested this in the comments on this answer) . (帽子提示pauloya谁在这个答案的评论中建议这一点)

#6楼

This happened to me too. 这也发生在我身上。 One dll was referenced twice: once directly (in references) and once indirectly (referenced by another referenced project). 一个dll被引用两次:一次直接(在引用中)和一次间接引用(由另一个引用的项目引用)。 I removed direct reference, cleaned & rebuilt solution. 我删除了直接参考,清理和重建的解决方案。 Problem fixed. 问题已解决。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值