Downgrade .net application Version
It's quite interesting to see that the project works just fine locally. And its 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. Sometime it may take a day to solve the problem.
Microsoft usually upgrades DLL files for bug fixing, for improving performances, for resolving the security-related issues, etc.
A solution to all the problem 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
can be solved by following 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
1) Open your project in visual studio
First, open your project in 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 "Application" tabs look at the "Target Framework" dropdown section.
- Here, we can see this project is running at 4.7.2 .net framework version.
Also, you will find all the package installed is targeting 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="126.96.36.199" targetFramework="net472" /> <package id="bootstrap" version="3.4.1" targetFramework="net472" /> <package id="jQuery" version="3.4.1" targetFramework="net472" /> ------ <package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" /> </packages>
3) Change the current .net framework to required .net framework
Here, I am having 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:
4)Update the NuGet package using the NuGet package console.
- Tool > Nuget Package Manager > Package Manager Console and type below command
5) Check .net framework installed in a package.config file.
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="Antlr" version="188.8.131.52" targetFramework="net452" /> <package id="bootstrap" version="3.4.1" targetFramework="net452" /> <package id="jQuery" version="3.4.1" targetFramework="net452" /> ------ <package id="Newtonsoft.Json" version="12.0.2" 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.
If you have 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.
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.