【问题标题】:Problem using Managed C++ (.Net 2.0) in .Net 2.0 project in VS2010在 VS2010 的 .Net 2.0 项目中使用托管 C++ (.Net 2.0) 的问题
【发布时间】:2011-06-23 16:33:16
【问题描述】:

我有两个项目:

1) 一个以 .net Framework 2.0 为目标的用 Visual C++ 2005 编写的项目。

2) Visual C# 2010 中的一个项目,它以 .net framework 2.0 为目标并包含 C++ DLL。

当我构建引用 C++ 程序集的 C# 项目时,我收到如下错误:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "ScannerWizard" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, 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.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "ScannerWizard" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System, 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.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "ScannerWizard" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "ScannerWizard" 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.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "ScannerWizard" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "ScannerWizard" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System.Data.SqlXml, 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.

如果我制作项目 4.0,它不会给出这些错误。显然,我不应该让它以 4.0 为目标来使用 2.0 程序集。

知道如何解决这个问题吗?

【问题讨论】:

  • 您是否转换了 C++/CLI 项目?不要,只添加引用。
  • 不,ScanWizard DLL 最后一次编译是在 4 年前,在 Visual C++ 2005 中。它没有被重新编译或任何东西。两者都不需要,但是如果我在编译时可以做一些不同的事情,我很乐意这样做。
  • 通过使用 ILSpy,我发现 VC++ DLL 引用了 MFCMIFC80,它依赖于 mscorlib 和 System.它不是使用 2.0 版本,而是使用系统上的最新版本,即 4.0。一定有办法阻止它这样做?
  • 警告导致通过该 DLL 公开的对象不可用。
  • 删除 DLL 似乎是一种解决问题的高风险方法(尽管它是成功的)。也许FuslogVW 可以让您找出正在加载的程序集链,而这反过来又可以让您write a policy 重定向到 2.0 程序集。

标签: c# .net visual-studio-2010 visual-c++


【解决方案1】:

C++ 项目使用 v100 平台工具集。这使得它依赖于某些库的 4.0 .NET 版本。将工具集更改为 v90 即可解决问题。如果您没有 v90 工具集,您可能需要安装它们...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 2015-02-12
    • 2010-09-28
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    相关资源
    最近更新 更多