How to Change .net Framework in Visual Studio 2017
.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 below step by step.
There are two ways of solving this issue.
- Downgrade your application to the required .net framework that the IIS server is asking.
- 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
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 for 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. Even the general users can do it. You don't have to mess with the registry. I will write about this in the next article.
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.
How to Change .net Framework in Visual Studio 2017
Source: https://ourtechroom.com/fix/how-to-downgrade-net-framework-version-in-visual-studio/