Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

downgrade .net 4.5 application to 4.0

Tags:

c#

.net

I want to downgrade a .net library from framework version 4.5 to .net 4.0.

I have several libs installed using nuget:

  • Microsoft.AspNet.WebApi.Client and it's dependencies:
  • Newtonsoft.Json
  • System.Net.Http (Microsoft .Net 4 HTTP Client Libraries)

I do the following:

  • In settings of each project in my solution I set target framework to 4.0 . After it I tried to rebuild my solution but of course without success because of error The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?), the same for HTTP Client libs

  • Using nuget ui manager I removed dependencies and tried to reinstall. But there is an error Could not install package 'Microsoft.AspNet.WebApi.Client 5.1.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

My question is: can I downgrade this project or I should replace these libs with some that support .net 4 and rewrite some parts of code?

like image 990
Peter Yeremenko Avatar asked Feb 28 '14 06:02

Peter Yeremenko


1 Answers

.NET 4.5 is an in-place upgrade for .NET 4.0 which means that the CLR is the same but new libraries are added as well as bug fixes and performance improvements, and both of the are point to .NET CLR 4.

In your case, as the .NET 4.5 already been installed, so The 4.5 update completely replaces the .NET 4.0 runtime.

Even if you change your project to .NET 4.0, the library used inside is still point to 4.5 but restricted to those available for 4.0, but behaviors may be different as what you expect in pure .NET 4.

So in order to downgrade your project from 4.5 to 4.0, I agree with you, you need to:

  1. Re-install your .NET framework to .NET 4 only (if you don't require .NET 4.5 any more)
  2. change project to point to .NET 4
  3. rewrite some part of the code which is not supported by .NET 4 (e.g. in your case, the Microsoft.AspNet.WebApi.Client 5.1.1 is come with WebApi2 in .NET 4.5, and you need to downgrade it to using the way as .NET 4 provided )

Hanselman and Rick had explained it very well.

like image 173
Panda Zhang Avatar answered Sep 28 '22 00:09

Panda Zhang