Fix "Unable to Find Package" NuGet Error in Visual Studio C#
.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.
So, you may be liking to downgrade the .net framework, so in this tutorial, I will guide you for the same.
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:
can be solved by following the below step-by-step.
There are two ways of solving this issue.
Doing Step 2 is beyond the scope of this tutorial. Here, I followed step 1.
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.
Also, you will find all the package installed is targeting the 4.7.2 .net framework as shown below.
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.
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.
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.
There are many questions where people are asking how to downgrade the .net framework installed on the computer. You can simply follow below steps:
Please keep the following things in mind:
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:
Ans: It comes with .Net framework 4.7 and all the lower and same versions of the .net application work fluently.