Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the TargetFramework settings mean in web.config in ASP .NET MVC?

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?

like image 500
g.pickardou Avatar asked Oct 21 '16 07:10

g.pickardou


People also ask

What is targetFramework?

A target framework moniker (TFM) is a standardized token format for specifying the target framework of a . NET app or library.

What is App settings in Web config?

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.

What is httpRuntime in Web config?

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.

What is controlRenderingCompatibilityVersion?

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.


Video Answer


1 Answers

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:

like image 78
Tetsuya Yamamoto Avatar answered Sep 21 '22 16:09

Tetsuya Yamamoto