【问题标题】:Indirect dependency - .NET2.0 - WMP.dll间接依赖 - .NET2.0 - WMP.dll
【发布时间】:2017-02-01 10:15:22
【问题描述】:

安装 Visual Studio 2017 RC 后,我有一些无法构建的代码。我已将其范围缩小到 WMP 和 .NET Framework 2(它在 Framework 4 下工作)

最基本的测试设置是 2 个项目:

项目一:

  • Windows 窗体应用程序
  • .NET 框架 2.0
  • 命名空间 WMPClient
  • 添加到 wmp.dll 的引用(已尝试 system32 和 syswow64)
  • 向 Form1.cs 添加了 Windows Media Player

项目 2:

  • 类库 (.NET Framework)
  • .NET Framework 2.0
  • 命名空间 WMPLib
  • 已添加到 WMPClient 的参考

两个项目都构建。

using WMPClient; 添加到Class1.cs(项目2)时,构建失败:

13 个错误行,例如 System.Windows.Forms, mscorlib, System

warning MSB3258: The primary reference "C:\WMPClient\bin\Debug\WMPClient.exe" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System.Windows.Forms, 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.

1 个这样的错误行:

error CS0246: The type or namespace name 'WMPClient' could not be found (are you missing a using directive or an assembly reference?)

同样的代码在 VS2013 下也不再工作了,但是在安装 VS2017 之前就可以了

【问题讨论】:

  • 有没有办法为 System.Windows.Form 版本 2.0.0.0 设置特定目标?
  • 每个系统参考的属性显示“运行时版本 = v2.0.50727” - 这适用于两个项目

标签: c# .net-2.0 visual-studio-2017


【解决方案1】:

它说您的“WMPClient.exe”具有更高版本的 .net 框架 4.0。 原则上,不能在较低的 .NET 版本项目中添加较高版本的库或命名空间。因此,要么使用 2.0 构建“WMPClient.exe”,要么将您的 Forms 项目升级到 4.0

【讨论】:

  • 两个项目在 Properties/Application csproj 中都设置为 Framework 2.0:v2.0
  • 运气好吗?我在从 VS2017 迁移到 VS2019(在新机器上)时遇到了同样类型的问题。
  • 在 .NET 框架 v3.5 上它不起作用。我在项目首选项中将我的应用程序升级到了 .NET framework v4.0,它对我有用。
猜你喜欢
  • 2010-12-11
  • 1970-01-01
  • 2020-09-03
  • 2015-06-24
  • 2021-04-14
  • 1970-01-01
  • 1970-01-01
  • 2011-10-16
  • 1970-01-01
相关资源
最近更新 更多