Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget does not update Package References in ASP.NET website

About: I have a ASP.NET website (not Web project) with 3 class library projects in the solution. Earlier I was using SVN but now Git is used source management. I have installed the git locally on a computer (used as server) and using it for merging the source code from other developers. Also, I am using Visual studio 2015 community edition which provides the tools to work with git.

Problem: After cloning the project from the master repository, I build the project to run it. Building the project shows a dialog box saying "Package Restore is in progress". This process creates a folder named "Packages" and that folder includes every package listed in the packages.config file. But after restoration completes, the project throws the following exception:

This exception shows for each package (Autofac here).

The type or namespace name 'Autofac' could not be found (are you missing a using directive or an assembly reference?)

Work around To Solve this problem, I need to uninstall each package and installed it again and problem is solved. This thing I need to do again and again for each developer machine, which is frustrating and time consuming too.

Does anyone has faced the same problem working with Nuget, git and website in ASP.NET.

like image 425
vivek Avatar asked Sep 01 '16 14:09

vivek


People also ask

How do I force a NuGet package to Update?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.

Where are NuGet packages references stored?

The location of the default global packages folder. The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux).


2 Answers

I faced a problem like this before. In my case, the reason was that I changed the project path (moved the project to another directory), and the path of the packages directory (that contains the NuGet packages) was stored in the csproj file for the old path, that is VS cannot restore NuGet packages. The solution for this was to edit the csproj manually and make it referring to the correct new packages path.

If this doesn't work for you, you can still use your workaround, but using the following PowerShell command (in NuGet Console) for simplicity:

Update-Package -reinstall -Project Your.Project.Name

Note: project name doesn't contain csproj extension, just the project name

like image 91
Sameh Deabes Avatar answered Sep 28 '22 05:09

Sameh Deabes


It is good practice to not put third party packages into source control. It bloats your repository (even on a large web application, the size of the external packages will massively out weigh your code).

If NuGet package restore is slow, you could look at using a local cache (this can be as simple as a shared folder) or a better internet connection.

That said, you should only have this problem once per machine. While the packages are downloading you could be giving the new team member an overview of the design…

like image 28
Richard Avatar answered Sep 28 '22 06:09

Richard