gpt4 book ai didi

asp.net - ASP .NET MVC 中 web.config 中的 TargetFramework 设置有何含义?

转载 作者:行者123 更新时间:2023-12-03 05:29:36 25 4
gpt4 key购买 nike

我们的 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下运行似乎是错误的...

显然我错过了一些东西,但是什么呢?

最佳答案

targetFramework的原因存在于 web.config是为了避免 .NET Framework 每个版本的重大更改之间出现兼容性问题。 targetFramework 之间的区别上compilationhttpRuntime属于每个开发和部署环境。

根据MSDN blog :

<compilation targetFramework="4.6" />

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

此元素确定编译期间使用的程序集版本,以从当前项目创建依赖项和相关程序集。

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

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

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

相关引用:

关于asp.net - ASP .NET MVC 中 web.config 中的 TargetFramework 设置有何含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40170567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com