这是什么真正的意思为目标的框架,以及如何最大限度地提高兼容性如何? [英] What does it really mean to target a framework, and how do I maximize compatibility?

查看:230
本文介绍了这是什么真正的意思为目标的框架,以及如何最大限度地提高兼容性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是混淆了我自从我第一次开始在C#中的编码。我的目标是创建一个将在最新的.NET框架的用户,不管这可能是运行的组件。我不希望需要安装.NET 4,但我想,如果用户拥有它,更重要的是,我希望它仍然可以工作,如果用户拥有使用它的只有的.NET 4及以下什么都没有。我开始怀疑这甚至是不可能的。

This has confused me ever since I first started coding in C#. My goal is to create an assembly that will run on the most recent .NET framework the user has, whatever that may be. I don't want to require .NET 4 to be installed, but I want to use it if the user has it, and more importantly, I want it to still work if the user has only .NET 4 and nothing below. I'm beginning to suspect this is not even possible.

我真的不明白我的选择,当我在Visual Studio中更改目标框架。这是否意味着将是这个版本,最多兼容?或将仅与该版本不兼容?好像是后者为止;我在虚拟机中的测试表明.NET 4的目标装配体,而.NET 4失败,和.NET 3.5有针对性的装配体,而.NET 3.5失败。 ?有没有办法来设置此这样我就可以达到最大的兼容性

I don't really understand what I'm selecting when I change the "Target Framework" in Visual Studio. Does that mean "will be compatible with this version and up"? Or "will be compatible with only this version"? It seems like it's the latter so far; my tests in virtual machines show .NET 4 targeted assemblies failing without .NET 4, and .NET 3.5 targeted assemblies failing without .NET 3.5. Is there no way to set this so I can achieve maximum compatibility?

更​​新:为了澄清,我有一个程序,面向.NET 2.这里的海报似乎表明。它应该与.NET 4但只有.NET 4中并没有什么在它之前,它无法加载的环境负载

UPDATE: To clarify, I have a program that targets .NET 2. The posters here seem to indicate that it should load with .NET 4. But in an environment with only .NET 4 and nothing before it, it fails to load.

UPDATE2:好了,想通了,但它的复杂得多比这里的海报似乎认为。我打开一个不同的问题来讨论的复杂性,但短期的版本是,你需要用℃的app.config中,supportedRuntime版本=V4.0/> 如果您想运行non-.NET 4组件的.NET 4.他们不会没有它加载它。

UPDATE2: Okay, figured it out, but it's far more complex than the posters here seem to think. I'm opening a different question to discuss the intricacies, but the short version is, you need an app.config with <supportedRuntime version="v4.0" /> in it if you want to run non-.NET 4 assemblies on .NET 4. They won't load without it.

推荐答案

该框架被设计成向后兼容;如果你有一个程序写在.NET 2.0中,你可以在4.0运行时运行它,因为没有框架的不断删除功能,以前的版本有(这就是为什么我们仍然有非泛型集合如ArrayList,即使他们支持泛型集合中使用)。但是,反过来不一定是真实的; 4.0应用程序不能保证在2.0运行,因为它可能需要的不在以前版本中的新的运行时的新功能。在任何情况下,如果你希望你的应用程序尝试在运行时版本中运行它不会特别针对,则必须使用SupportedRuntime元素指定在App.config。

The frameworks are designed to be backwards-compatible; if you have a program written in .NET 2.0, you can run it in the 4.0 runtime, because none of the frameworks ever remove functionality that a prior version had (which is why we still have the non-generic collections like ArrayList, even though they're deprecated in favor of generic collections). However, the reverse is not necessarily true; a 4.0 app is not guaranteed to run in 2.0, because it MAY take advantage of new features of the new runtime that are not available in prior versions. In any case, if you want your app to attempt to run on runtime versions it does not specifically target, you must specify that in the app.config using SupportedRuntime elements.

为了回答您的具体问题,你可以做你想做的以下基本步骤:

To answer your specific question, you can do what you want with the following basic procedure:


  • 开发你的应用程序为目标的最早要支持框架的版本。这将禁用(在4.0象中的LINQ 3.5,动态类型)进入新的运行时的新功能,确保您的应用程序不会要求不能由任何支持的运行环境下提供的任何功能。

  • Develop your app to target the EARLIEST framework version that you want to support. This will disable access to newer features of newer runtimes (like Linq in 3.5, and dynamic typing in 4.0) ensuring your app will not require any feature that cannot be provided by any of the supported runtimes.

指定可以接受的在您的app.config文件使用SupportedRuntime元素应用程序的框架。这将告诉初始化中,你的应用程序将运行,如果它不能找到有针对性的版本,其他任何人都可以接受的运行本地代码。我相信行为是寻找有针对性的框架首先,如果不使用它应该使用最新支持的运行时。

Specify the frameworks that are acceptable to your application by using the SupportedRuntime element in your app.config file. This will tell the native code that initializes the runtime in which your app will run that if it can't find the targeted version, any of the others are acceptable. I believe the behavior is to look for the targeted framework first, and if not available it should use the newest supported runtime.

这篇关于这是什么真正的意思为目标的框架,以及如何最大限度地提高兼容性如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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