ASP .NET MVC中的web.config中的TargetFramework设置是什么意思? [英] What do the TargetFramework settings mean in web.config in ASP .NET MVC?

查看:782
本文介绍了ASP .NET MVC中的web.config中的TargetFramework设置是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的ASP.NET MVC 5 Web应用程序之一具有以下web.config设置:

<system.web>
  <compilation debug="true" targetFramework="4.6" />
  <httpRuntime targetFramework="4.5" />
  <!--... many other things -->
</system.web>

尚不清楚为什么有两个targetFramework设置,并且编译目标4.6然后尝试在4.5下运行似乎是错误的...

很明显,我缺少了什么,但是呢?

解决方案

web.config中存在targetFramework的原因是为了避免在对每个.NET Framework版本进行重大更改之间存在兼容性问题. compilationhttpRuntime上的targetFramework之间的差异属于每个开发和部署环境.

根据 MSDN博客:

<compilation targetFramework="4.6" />

选择哪个版本的.NET Framework参考程序集是 在执行编译时使用. (注意:Visual Studio要求 即使我们自动推断出此元素,它也会出现在Web.config中.)

此元素确定在编译过程中用于从当前项目创建依赖项和相关程序集的程序集版本.

<httpRuntime targetFramework="4.5" />表示当前项目设计为使用.NET 4.5运行时程序集,而无需在加载到内存中之前重新编译部署计算机中的现有项目程序集.

因此,我们可以得出结论,在httpRuntime元素中的targetFramework上定义的版本号旨在在运行时使用时维护已编译项目与可用程序集之间的兼容性,具体取决于目标计算机中使用的运行时文件的版本. >

因此,在您的情况下,这不是错误的行为,项目创建者只想保持运行时兼容性为目标计算机中具有类似特征的最低运行时版本(即4.5版),即使使用.NET程序集的较新版本. 4.5和4.6之间的差异相对较小,因此在这种情况下仍可以将运行时版本降至4.5.

相关参考文献:

https://msdn.microsoft.com/en-us/library/dn833123(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dn833125(v=vs.110).aspx

One of our ASP.NET MVC 5 web applications has the following web.config settings:

<system.web>
  <compilation debug="true" targetFramework="4.6" />
  <httpRuntime targetFramework="4.5" />
  <!--... many other things -->
</system.web>

It is not clear why are two targetFramework settings, and it seems to be wrong to compile targeting 4.6 then trying to run under 4.5...

Obviously I am missing something, but what?

解决方案

The reason of targetFramework existence in web.config is to keep compatibility issues out between breaking changes for each version of .NET Framework. The difference between targetFramework on compilation and httpRuntime belongs to each development and deployment environment.

According to MSDN blog:

<compilation targetFramework="4.6" />

Selects which version of the .NET Framework’s reference assemblies are used when performing compilation. (Note: Visual Studio requires that this element be present in Web.config, even though we auto-infer it.)

This element determines the assembly version used during compilation to create dependencies and related assemblies from current project.

<httpRuntime targetFramework="4.5" /> means that current project designed to use .NET 4.5 runtime assemblies without recompiling existing project assemblies in deployment machine before loading it into memory.

Hence, we can conclude that version number defined on targetFramework in httpRuntime element designed to maintain compatibility between compiled project and available assemblies in runtime usage, depending on which version of runtime files being used in target machine.

Thus, in your case, this is not a wrong behavior, the project creator(s) simply want to keep runtime compatibility to lowest runtime version available in target machine with similar characteristics (i.e. version 4.5), even the project compiled with newer version of .NET assemblies. The difference between version 4.5 and 4.6 is relatively small, thus keeping runtime version down to 4.5 still acceptable on this context.

Related references:

https://msdn.microsoft.com/en-us/library/dn833123(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dn833125(v=vs.110).aspx

这篇关于ASP .NET MVC中的web.config中的TargetFramework设置是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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