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?
A target framework moniker (TFM) is a standardized token format for specifying the target framework of a . NET app or library.
The <appSettings> element of a web. config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work.
The HttpRuntimeSection allows you to handle those parameters that affect the behavior of the ASP.NET runtime. It refers to the node in the configuration file that is indicated by the <httpRuntime> element and can be used at any level in the configuration hierarchy.
Remarks. This value is set by the controlRenderingCompatibilityVersion attribute of the pages element in the Web. config file. The value of this property is the default value for the Control. RenderingCompatibility property.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With