MarsRoverII
MarsRoverII

Reputation: 159

An Asp.NET MVC application is built with .net framework version 4.5, I want to run the application on a higher .net framework that is 4.7.2

Can you help me on the below query? An Asp.NET MVC application is built with .net framework version 4.5, I want to run that application on a higher .Net Framework version that is v4.7.2.

Will it work, if i change the version in the web.config file only? Or i have to build the application with the higher version in Visual Studio as well?

Thanks in advance.

Upvotes: 0

Views: 1513

Answers (2)

JoeBilly
JoeBilly

Reputation: 3107

Target Framework

Besides the CLR which is directly related to the runtime, the targetFramework will tell .NET which assemblies it should target.

<compilation targetFramework="4.x.x"/>

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.)

<httpRuntime targetFramework="4.x.x"/>

This was introduced to do what you want : opting for 4.7 behaviors with a 4.5 developed application. Note that you may have some behaviors, it is not magic :) (even if in your case 4.5 to 4.7 will not be a problem IMHO).

The effect of this attribute is twofold. First, it controls the CLR’s quirks mode behavior, just like the <supportedRuntime> element does in a console application. Second, <httpRuntime targetFramework="4.5" /> is a shortcut that allows the ASP.NET runtime to infer a wide array of configuration settings.

Check https://blogs.msdn.microsoft.com/webdev/2012/11/19/all-about-httpruntime-targetframework/

Assembly Binding

There is also assembling binding in the web.config, it is intended to bind a range of assembly versions to a specific version.

The thing is .NET Framework assemblies (not .NET Core ones) are based on the CLR version. As far as I know, all assemblies included in the framework (not satellites ones like MVC) will be 4.0.0.0. So you cannot bind a 4.x Framework assembly to a 4.7 framework because they will have the same assembly version.

But you can bind your external (NuGet) dependency.

Anyway, except if you have different web server configurations with different frameworks installed, the cleanest way is to recompile your application by changing the target framework in Visual Studio project properties as already said.

Upvotes: 1

markaaronky
markaaronky

Reputation: 1305

I would strongly recommend making the change to the PROJECT properties in Visual Studio (in Solution Explorer, right click the Project | Properties | Target Framework (dropdown);

If you look at the markup of a project file (.csproj), you'll see the targeted framework referenced there (as a result of your project settings). Code snippet from a 4.6.1-targeted *.csproj file here:

    **<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>**
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>false</UseIISExpress>

Making a web.config change could/would not, AFAIK, affect this value (and therefore any generated assemblies) in any way.

Upvotes: 0

Related Questions