如果我删除自动添加supportedRuntime元素,会发生什么? [英] What happens if I remove the auto added supportedRuntime element?

查看:196
本文介绍了如果我删除自动添加supportedRuntime元素,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的项目的目标4.0。 我更新到4.5和VS添加

I have my project target 4.0. I updated it to 4.5 and VS added

<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

在改变TargetFrameworkVersion的顶部,我很好奇,如果这是多余的。 我的理解是,如果运行时没有找到supportedRuntime,它使用了用于构建EXE的.NET版本。因此,在这种情况下,使用的exe构建4.5,它也已说使用4.5。难道不同的表现,我是否有这个或没有,一台机器,只有4.0上运行它?

On top of changing TargetFrameworkVersion and I am curious if this is redundant. My understanding is that if runtime doesn't find supportedRuntime, it uses the .net version used to build exe. So in this case, the exe is built using 4.5 and it also has saying to use 4.5. Would it behave differently whether i have this or not and run it on a machine that only has 4.0?

推荐答案

MSDN文档并没有给出任何这很好的解释,但我发现在Scott Hanselman博客文章题为<一href="http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx">.NET版本控制和多目标 - .NET 4.5就地升级到.NET 4.0 ,揭示了:

The MSDN documentation doesn't give any good explanations of this, but I found a blog post by Scott Hanselman titled ".NET Versioning and Multi-Targeting - .NET 4.5 is an in-place upgrade to .NET 4.0" that reveals:

如果你是一个客户端应用程序,如的WinForms,控制台,WPF,等等,这一切都是自动的。你的app.config包含事实,你需要.NET 4.5,你甚至会得到提示进行安装。

If you are making a client app, like WinForms, Console, WPF, etc, this is all automatic. Your app.config contains that fact that you need .NET 4.5 and you'll even get a prompt to install it.

因此​​,配置项是关于如果他们的机器上使用.NET 4.0用户(而不是.NET 4.5)尝试运行.NET 4.5的应用程序会发生什么。无论.NET 4.0和.NET 4.5是建立在CLR版本4,所以他们在理论上兼容;相同的二进制格式和所有。构建在.NET 4.0和一个内置在.NET 4.5二进制之间唯一的区别是它们所引用的库​​。

So the config entry is all about what happens if a user with .NET 4.0 on their machine (but not .NET 4.5) tries to run your .NET 4.5 app. Both .NET 4.0 and .NET 4.5 are built on version 4 of the CLR, so they're theoretically compatible; same binary formats and all that. The only difference between a binary built against .NET 4.0 and one built against .NET 4.5 is the libraries they reference.

所以编译.NET 4.5的应用程序可以运行的计算机只安装了.NET 4.0。但是,如果您试图使用未在4.0存在任何的API得到一个运行时异常。

So an app compiled for .NET 4.5 could run on a computer with only .NET 4.0 installed. However, it would get a runtime exception if you tried to use any APIs that didn't exist in 4.0.

如果您有这方面的配置文件项,,然后用户使用.NET 4.0尝试运行你的应用程序,该应用程序将无法运行,并且用户将被提示安装.NET 4.5。 (见截图在斯科特的博客文章。)这是一个很好的默认对大多数人来说。

If you have this config file entry, and a user with .NET 4.0 tries to run your app, the app will not run, and the user will be prompted to install .NET 4.5. (See screenshot in Scott's blog post.) This is a good default for most people.

如果您还没有配置文件条目,,然后使用.NET 4.0的用户将可以运行你的应用程序,但会得到一个运行时异常,如果您尝试调用任何方法或使用添加于4.5的任何类型。这将是一个很大的痛苦你作为一个开发人员和测试人员。如果你有,你应该只做到这一点的的具体要求的你的应用程序必须运行在.NET 4.0中的的必须利用新的4.5功能,如果他们是present(而你必须要小心异常处理和对两个版本进行广泛的测试)。

If you don't have the config file entry, then a user with .NET 4.0 will be able to run your app, but will get a runtime exception if you try to call any methods or use any types that were added in 4.5. This will be a big pain for you as a developer and for your testers. You should only do this if you have specific requirements that your app must run on .NET 4.0 and must take advantage of new 4.5 features if they're present (and you'll have to be careful about exception handling and test extensively on both versions).

如果你想成为的能够的对.NET 4.0上运行,但不需要任何新的4.5的API,,然后你的生活更简单:只要进入项目属性的编译选项卡,目标.NET 4.0。那么编译器将确保你不叫未在4.0存在任何的API,你的应用程序将同时支持.NET 4.0和.NET 4.5的机器运行成功。

If you want to be able to run on .NET 4.0, but don't need any new 4.5 APIs, then your life is much simpler: just go to the Build tab of Project Properties, and target .NET 4.0. Then the compiler will ensure that you don't call any APIs that didn't exist in 4.0, and your app will run successfully on both .NET 4.0 and .NET 4.5 machines.

这篇关于如果我删除自动添加supportedRuntime元素,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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