【问题标题】:Program written using .net 4.0 but I need this application to run on computers running .net 2.0使用 .net 4.0 编写的程序,但我需要此应用程序在运行 .net 2.0 的计算机上运行
【发布时间】:2011-11-17 06:48:22
【问题描述】:

这个问题单看标题就应该很清楚了,但让我更详细地解释一下。我刚刚在 .Net 4.0 框架中编写完我的应用程序(见下图)。在意识到我需要我的应用程序与最早版本的 .Net 框架兼容后,我返回并更改了 Visual Studio 的“属性”窗口中的目标框架。不幸的是,这样做给我留下了一长串令人痛苦的警告——以及一个严重错误。我很好奇是否有人对如何让我的应用程序(使用 .Net 4.0 框架编写)在运行 .Net 2.0 框架的环境中运行有一些解决方案。

原创编译

错误列表:

谢谢, 埃文

编辑:

我知道第二张图片对我们大多数人来说并不完全可见,所以我将在下面发布错误:

Warning 9   The referenced component 'System.Xml.Linq' could not be found.  
Warning 10  The referenced component 'System.Data.DataSetExtensions' could not be found.    
Warning 8   The referenced component 'System.Core' could not be found.  
Warning 11  The referenced component 'Microsoft.CSharp' could not be found.     
Warning 4   The primary reference "System.Xml.Linq", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Xml.Linq" or retarget your application to a framework version which contains "System.Xml.Linq".   Protection
Warning 2   The primary reference "System.Xml.Linq" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Xml.Linq" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".   Protection
Warning 5   The primary reference "System.Data.DataSetExtensions", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Data.DataSetExtensions" or retarget your application to a framework version which contains "System.Data.DataSetExtensions". Protection
Warning 3   The primary reference "System.Data.DataSetExtensions" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Data.DataSetExtensions" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".   Protection
Warning 1   The primary reference "System.Core", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Core" or retarget your application to a framework version which contains "System.Core".   Protection
Warning 6   The primary reference "Microsoft.CSharp", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.CSharp" or retarget your application to a framework version which contains "Microsoft.CSharp".    Protection
Error   7   Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Line 123, position 5.    C:\Users\FARINA_EVAN\Documents\Programming\C#\Run Time Crypter\Run Time Crypter\Properties\Resources.resx   123 5   Protection

【问题讨论】:

  • 通过重新编码以排除任何 4.0 特定功能。唉,我认为这里没有捷径。
  • 如果您右键单击并选择查看图像,图像实际上是非常可见的。

标签: c# .net winforms


【解决方案1】:

当您创建一个面向 .NET 4.0 的新项目时,Visual Studio 会自动添加对一些常用 :NET 4.0 程序集的引用。但是,在更改目标平台时,这些引用不会被删除,因此需要手动删除,因为您无法从 .NET 2.0 应用程序引用 .NET 4.0 程序集。

所以从删除这些错误的引用开始,看看是否还有任何错误。如果您使用了 .NET 2.0 中不可用的任何 .NET 功能,则可能需要更改某些源代码,或者如果缺少对 .NET 2.0 程序集的新引用,则可能需要添加它们。

出现的任何编译器错误都可能为您指明正确的方向。

【讨论】:

    【解决方案2】:

    是的,但是您需要删除任何引用大于 2 的 .net 版本的代码。要清除上述这些错误,您需要删除对所有显示“引用的组件 xx 可以找不到”。此外,您需要搜索资源、配置等文件,以替换任何 .net 4 对 .net 2 -> 从 4.0.0.0 到 2.0.0.0 的引用,或者如果引用在 .net 中不存在,则完全删除它们。净 2.

    【讨论】:

    • 那么,当我重新添加时,Visual Studio 会自动寻找每个 dll 的 .net 2.0 版本吗?
    • @Evan:其中一些 DLL 没有 .NET 2.0 等效项。
    【解决方案3】:

    错误消息告诉您出了什么问题,在这种情况下,您的项目中有无法解析的引用。展开项目树中的引用节点并删除带有警告图标的引用。

    如果您尝试在此之后进行编译,您可能会收到有关您使用的类、命名空间或关键字的其他错误,这些错误在 .NET 2.0 中不可用。您必须删除这些或更改您的代码。

    【讨论】:

    • 我知道出了什么问题,恕我直言。我不知道解决问题的最佳方法。我不想在我的应用程序中搞砸任何事情..
    【解决方案4】:

    由于 Linq 在 .NET 2.0 中不可用,您可以尝试 LinqBridge 作为替代。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-20
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多