How to downgrade .net application framework version in visual studio?


๐Ÿ‘คย Diwas Poudel ย ย  ๐Ÿ•’ 31 May 2023 ย ย  ๐Ÿ“ FIX

.Net framework is a powerful software development framework developed by Microsoft for building, deploying, and running applications in windows machine.Net developer uses .Net framework for developing desktop and web applications. But this framework sometimes may problem for you. You might face the situation like you are developing a web application using the latest version of the .net framework. Let's say .net framework 4.8 and at the time of deploying the server does not have .net framework 4.8. Then you have two options:

1. Downgrade .net framework in application from visual studio

2.ย  Install .net framework 4.8 on the server or downgrade to lower version so that server has that version already installed. Upgrading .net framework sometimes create some issues like some .net framework application which is already in the server might not work correctly.

From Microsoft Website

Talking especially about 4.x ( 4.0 to 4.8)
1 . If you have installed the latest version of the .net framework, then you do not have to uninstall the previous version.
2. If your OS or server has been preinstalled with a particular .Net framework version, then you cannot install the older version on the same machine.
3. If you have a newer version, you cannot install the previous .net framework version.
4. Only one 4.x version will exist in your system and is backward compatible.
5. If you like the older version then first remove the newer version and then install an older version

So, you may be liking to downgrade the .net framework, so in this tutorial, I will guide you for the same.

Downgrade .net application Version

It's quite interesting to see that the project works just fine locally. And it's is time to upload to the server. You have uploaded successfully. But you try to access the site in the browser you may get NuGet package compatibility-related issues. And this may irritate you. Sometimes it may take a day to solve the problem.

Microsoft usually upgrades DLL files for bug fixing, improving performances, resolving security-related issues, etc.

A solution to all the problems like:

  • VS 2019 downgrades .NET 4.7 projects to target framework version 4.6.1.
  • How to downgrade the target framework from 4.5 to 4.0?
  • How to downgrade the target framework from 4.7.2 to 4.5.2?
  • Downgrading .NET Framework causingย  packages related issues
  • Downgrade Net Framework 4.8 to 4.7.03

can be solved by following the below step-by-step.

There are two ways of solving this issue.

  1. Downgrade your application to the required .net framework that the IIS server is asking.
  2. Upgrade IIS Server to the version that your application is asking.

Doing Step 2 is beyond the scope of this tutorial. Here, I followed step 1.

Downgrade .net application (Project Level)

1) Open your project in a visual studio

First, open your project in a visual studio.ย 

2) Check the .net framework installed in your application.

  • Right-click on your project file (not a solution)ย 
  • Click on "Properties".
  • Then under the "Application" tabs look at the "Target Framework" dropdown section.
  • Here, we can see this project is running at the 4.7.2 .net framework version.

Also, you will find all the package installed is targeting the 4.7.2 .net framework as shown below.

  • Open packages.config file.

packages.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net472" />
  <package id="bootstrap" version="3.4.1" targetFramework="net472" />
  <package id="elmah" version="1.2.2" targetFramework="net472" />
  <package id="elmah.corelibrary" version="1.2.2" targetFramework="net472" />
  <package id="Elmah.Mvc" version="2.1.2" targetFramework="net472" />
  <package id="EntityFramework" version="6.3.0" targetFramework="net472" />
  <package id="EntityFramework6.Npgsql" version="6.3.0" targetFramework="net472" />
  <package id="EPPlus" version="5.1.2" targetFramework="net472" />
  <package id="jQuery" version="3.3.1" targetFramework="net472" />

---
</packages>

3) Change the current.net framework to the required .net framework

Here, I am having a 4.7.2 .net framework and I am targeting the .net framework to 4.5.2ย  as shown below.

Then you may get a warning message as shown below.

 
 Warning: Some NuGet packages were installed using a target framework different from the current target framework and may need to be 
reinstalled. Visit https://docs.nuget.org/docs/workflows/reinstalling-packages for more information. Packages affected:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
DowngradeApplication

4)Update the NuGet package using the NuGet package console.

  • Tool > Nuget Package Manager > Package Manager Consoleย  ย and type below command

๐Ÿ’ก Note! You must have NuGet version 2.1 for using the package manager console. For version less than Nuget version 2.1 visit here. ๐Ÿ‘‰
ย 

5) Check the .net framework installed in a package.config file.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net452" />
  <package id="bootstrap" version="3.4.1" targetFramework="net452" />
  <package id="elmah" version="1.2.2" targetFramework="net472" />
  <package id="elmah.corelibrary" version="1.2.2" targetFramework="net452" />
  <package id="Elmah.Mvc" version="2.1.2" targetFramework="net452" />
  <package id="EntityFramework" version="6.3.0" targetFramework="net452" />
  <package id="EntityFramework6.Npgsql" version="6.3.0" targetFramework="net452" />
  <package id="EPPlus" version="5.1.2" targetFramework="net452" />
  <package id="jQuery" version="3.3.1" targetFramework="net452" />

---
</packages>
  
  
  
  
  
  
  
  
  

---

Now, our application is targeting to 4.5.2 .net framework.

So, finally, we have successfully downgraded the .net framework.

Note: If you have multiple projects in a solution then repeat the same steps as above for all projects.

Downgrade .net framework for NuGet version < 2.1 (Project Level)

If you have a NuGet version less than 2.1 then the above method doesn't work. Follow the below steps:

NuGet 2.0 and Less doesn't deal very well with re-targeting your applications. To change the target frameworks of your packages, you will need to uninstall each package and reinstall all those packages again.

Note:

While downgrading the .net framework for the project, some errors may occur at a compiled time and can't reference the namespace. So, some packages and libraries may not work if you downgrade so read the documentation properly, and if all of your packages support on lower .net version then Ok and move forward with the process.

Downgrade .net framework in Computer (OS level)

There are many questions where people are asking how to downgrade the .net framework installed on the computer. You can simply follow below steps:

  1. Goto search and type "Windows features".
  2. Select the Turn Windows Features ON or OFF option from the list.
  3. Scroll down and find out the .Net framework version you have to downgrade.
  4. Uncheck it then You will get a message stating "The following Windows features will also be turned off becauseย 
    they are dependent on .Net Framework xxx. Do you want to continue? Just click on "Yes"
  5. Next, click on the "Ok" Button.
  6. Now Windows will automatically uninstall that particular .Net framework version.
  7. Once uninstall is completed you can again install your desired older version.

Please keep the following things in mind:

  • If you do not know properly what you're doing then it's better to backup up your data before you downgrade the .Net framework.
  • It is advised to always downgrade the .NET framework on a test machine and if successful then only do the same in production.
  • Seek the help of a developer if you feel uncomfortable.

Conclusion

It seems that it can be simple to downgrade a project, but it takes a long time to find a solution. Thanks, visual studio for such wonderful tools.

FAQ:

What .net framework comes with Windows Server 2016?

Ans: It comes with .Net framework 4.7 and all the lower and same versions of the .net application work fluently.