确定对不正确 .NET Framework 版本的间接依赖的来源 [英] Determine the source of an indirect dependency on incorrect .NET Framework version

查看:91
本文介绍了确定对不正确 .NET Framework 版本的间接依赖的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何确定此构建错误的来源;

Warning 4 无法解析主要引用MyNamespace.MyProject",因为它间接依赖于 .NET Framework 程序集System.Xml, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" 比4.0.0.0"版本更高当前目标框架中的版本2.0.0.0".MyNamespace.MyOtherProject

我了解此错误的含义(以及其他 5 个人在同一个项目中喜欢它),但在我的情况下我不知道如何解决它.本例中的主要引用"(MyNamespace.MyProject)与 .NET 4.0.x 没有直接依赖关系.

主要引用仅依赖于我的另一个项目 (MyNamespace.MyCoreProject),构建的源项目 (MyNamespace.MyOtherProject) 也直接依赖于该项目.并且构建并没有抱怨那个项目间接引用了 .NET 4.0.x,所以我想我可以排除这一点.

主要引用直接依赖于三 (3) 个 3rd 方 DLL,所有这些 DLL 都面向 .NET 2.0.

我使用 dotPeek 来检查构建的库,但看不到任何对使用 .NET 4.0 的任何引用.

工作中唯一的其他潜在扳手是使用 PostSharp,它被 'MyNamespace.MyCoreProject' 直接引用(由主要引用项目引用),这可能是导致问题的原因,因为我相信有一个相关的VS2010 引用 PostSharp.dll 时的错误 (http://www.sharpcrafters.com/forum/Topic4444-4-1.aspx#bm4462),但是我也从构建链中删除了它,但仍然看到这个错误,所以我假设我也可以排除.

如果有人能告诉我为什么会这样,太棒了!如果没有,有关如何确定未命名的间接引用"是什么的一些指导将同样有帮助!

顺便说一下,我已经尝试了以下所有工具来获取一些信息,但它们并没有告诉我太多我不知道的信息(这是有问题的 DLL 的直接依赖项);- .NET 反射器- 点窥- IldAsm- 取决于(依赖沃克)

解决方案

虽然我实际上还没有找到一个好的方法来实际解决确定 MsBuild 如何确定它使用的引用的问题(为什么它不只是告诉我如何它提出了这些间接引用,而不是让我猜测我不知道......)我已经解决了我的问题.

最后,我基本上删除了主要引用"项目中的所有引用(这需要逐段排除所有代码 - 一个有点痛苦的过程)以确定对 .NET 4.0 库的假定间接引用的来源是由被引用的第 3 方 DLL 引起的.

但是,我确实相信这个问题背后的 MsBuild 存在一个错误,因为;

  1. 浏览"将第 3 方 DLL 引用到我机器上的特定 DLL 文件 - 一个非常明确地仅依赖于 .NET 2.0 的文件
  2. 在构建中将特定版本"设置为 true 无法解决此问题
  3. MsBuild 似乎要向 GAC 提交此 DLL 的不同版本并导致不正确的引用错误.

现在,另一个好奇是我已经有一段时间没有接触或更改相关的库了,所以这只是由于其他一些不相关的原因才开始发生 - 可能是什么,我不知道.

最后,我发现解决此问题的唯一方法是为每个相关库运行 gacutil/u 以删除以前安装/使用的 4.0 库版本.(包里大约有 40 个,所以这也很痛苦!因为包的卸载程序没有删除 GAC 中的库)

这似乎让 msbuild 开始使用我告诉它的引用,而不是自己想出使用此文件"和使用此特定版本"的含义.>

解决了,但我会喜欢一种更简洁的方法来做到这一点!

I would like to know how I can determine the source of this build error;

Warning 4   The primary reference "MyNamespace.MyProject" could not be resolved because 
   it has an indirect dependency on the .NET Framework assembly "System.Xml, Version=4.0.0.0,
   Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than
   the version "2.0.0.0" in the current target framework.   MyNamespace.MyOtherProject

I understand the meaning of this error (and the 5 others like it for this same project), but I cannot work out how to resolve it in my case. The 'primary reference' in this case (MyNamespace.MyProject) has no direct dependencies on .NET 4.0.x.

The primary reference depends on only one other project of mine (MyNamespace.MyCoreProject), which the source project for the build (MyNamespace.MyOtherProject) also depends directly on. And the build is not complaining about that project having indirect references to .NET 4.0.x, so I assume I can rule that out.

The primary reference has a direct dependency on three (3) 3rd party DLLs, all of which also Target .NET 2.0.

I have employed dotPeek to examine the built libraries, and cannot see any reference to anything using .NET 4.0.

The only other potential spanner in the works is the use of PostSharp, which is directly referenced by 'MyNamespace.MyCoreProject' (referenced by the primary reference project), which may be causing the problem, as I believe there is a related VS2010 bug when referencing PostSharp.dll (http://www.sharpcrafters.com/forum/Topic4444-4-1.aspx#bm4462), however I also removed that from the build chain and still see this error, so I assume I can also rule that out.

If someone can tell me why this is happening, fantastic! If not, some direction on how to work out what the unnamaed 'indirect reference' is would be just as helpful!

Incidentally, I have tried all of the following tools to get some info, but they're not telling me much I didn't already know (which is the direct dependencies of the DLL in question); - .NET Reflector - dotPeek - IldAsm - Depends (Dependency Walker)

解决方案

Whilst I have not actually worked out a good way to actually solve the problem of determining how MsBuild determines the references it uses (why it does not just tell me how it comes up with these indirect references, instead of making me guess I don't know...) I have solved my problem.

In the end, I basically removed all references in the 'primary reference' project, (which required excluding all code piece by piece - a somewhat painful process) to determine that the source of the supposed indirect reference to .NET 4.0 libs was caused by a 3rd party DLL that was referenced.

However, I do believe there is a bug in MsBuild behind this problem, as;

  1. The 3rd party DLL was referenced by 'Browse' to a specific DLL file on my machine - one that VERY EXPLICITLY depends only on .NET 2.0
  2. Setting 'Specific Version' to true in the build did nothing to fix this
  3. MsBuild appeared to be going to the GAC for a different version of this DLL and causing the incorrect reference error.

Now, another curiosity is that I've not touched or changed the relevant libs in some time, so this has just started happening for some other unrelated reason - what that may be, I don't know.

In the end, the only way I found to solve this issue was to run gacutil /u for each of the relevant libs to remove previously installed/used versions of the 4.0 libs. (There were about 40 in the package, so that was also painful! as the package's uninstaller did not remove the libs in the GAC)

This seems to have let msbuild start using the references I told it to, rather than coming up with its own idea of what 'use this file' and 'use this specific version means.

Solved, but I would have loved a cleaner way to do this!

这篇关于确定对不正确 .NET Framework 版本的间接依赖的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆