设置“目标框架"的作用是什么?在Visual Studio中 [英] What is the effect of setting a "Target framework" in Visual Studio

查看:897
本文介绍了设置“目标框架"的作用是什么?在Visual Studio中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,您可以为项目设置目标框架".

In Visual Studio you can set the "Target framework" for your project.

或多或少的常识是,如果将目标框架"设置为(例如).NET 4.5.2,则在仅安装.NET 4.5.1的计算机上,该应用程序将无法运行.

It is more or less common knowledge that if you set "Target framework" to (for example) .NET 4.5.2 the application won't run when on a machine that has only .NET 4.5.1 installed.

第一个问题:这是真的吗? 第二个问题:该设置还有其他影响吗?

First question: Is that really true? Second question: Are there any other effects of that setting?

目前,在我公司中,我们正在为.NET 4.5.2设置应用程序的最低要求.因此,我们当然要设置目标框架". 我们正在使用的内部库设置为.NET 4.5的目标框架".而且我们想知道这是否有所作为,还是应该将该库设置为.NET 4.5.2..

In my company we are setting the minimum requirement for an application to .NET 4.5.2 at the moment. And thus we are settings the "Target framework" of course. An internal library we are using is set to a "Target framework" of .NET 4.5. And we were wondering if that even made a difference or if the library should also be set to .NET 4.5.2.

我认为这无关紧要,但是我没有找到有关该主题的任何资源.你觉得呢?

In my opinion it should not matter but I didn't find any resources on that topic. What do you think?

推荐答案

第一个问题:真的吗?

这取决于.如果您的应用程序针对4.5.2,但未使用4.5.2中的任何内容,但未使用4.5.1中的任何内容,那么理论上它将在仅安装4.5.1的计算机上正常运行. (可能会检查程序/安装程序是否运行,以检查是否已安装4.5.2,但您可以禁用此功能)

It depends. If your application is targeted for 4.5.2 but doesn't use anything that is in 4.5.2 but not in 4.5.1, then theoretically it will run fine on a machine with only 4.5.1 installed. (There may be check the program/installer runs to check that 4.5.2 is installed, but you can disable this)

但是,如果您的应用程序使用4.5.2中的功能(或其他功能),而不是4.5.1中的功能,则您的应用程序将无法在4.5.1的计算机上运行.

However, if your application uses functions (or whatever) that are in 4.5.2 but NOT in 4.5.1, then your application will not run on the 4.5.1 machine.

作为一般规则,您应该仅将目标设置为所需的最小值. IE.如果您不使用4.5.2特定功能,则不要将其定位为4.5.2,因为没有必要.如果可以的话,最好将目标设置为4.5.1,因为您可以在4.5.2和4.5.1的计算机上正常运行它.目标越低越好,因为它有可能在更多计算机上运行.

As a general rule, you should only set the target to be the minimum that is required. I.e. if you don't use 4.5.2 specific functions, then don't target it for 4.5.2 as there is no need. It is always better to set the target to 4.5.1 if you can, as you can run it fine on both 4.5.2 and 4.5.1 machines. Lower target the better as the chances are it will run on more machines.

所有其他框架也遵循相同的规则(即,如果您的Android应用仅需要18级API,则将目标(或至少最低目标)设置为18,而不是更高的目标.

The same rule goes for all other frameworks as well, (I.e. if your Android app only needs level 18 API, then set the target (or at least the minimum target) to be 18 rather than anything higher.

这篇关于设置“目标框架"的作用是什么?在Visual Studio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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