8

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.

4
  • Does the Autofac package exist in the Git repo? Meaning, can you se that the package is added Commented Oct 6, 2016 at 5:52
  • Packages are not added in git repo. The project has package.config file. I use default visual studio git setting and it does not add packages folder in the main git repo. Also, I do not see bin folder in the website when cloned on a system. Commented Oct 6, 2016 at 5:56
  • OK, does the Autofac version which the package.config file refer to exist? Commented Oct 6, 2016 at 5:59
  • 1
    After cloning the project from the server, there is no packages folder. When I start the debugging, it shows a dialog box saying that "Restoring packages". It does create a folder and there are packages after this process. But I get reference error after package restore is done. The thing is that the nuget is not adding/updating the reference in the solution references. It does not show packages references in "property Pages -> references list". Manually adding the package references works too, but I wanted to know the reason why it does not work as In Open source projects it works very well. Commented Oct 6, 2016 at 6:19

5 Answers 5

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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…

3 Comments

Thanks for the reply, But I think, i was unable to ask my question properly. I have no problem with package installation every time. When I set up the project on other machine, The project does not build after the package installation is done. It throws exceptions for each package and the work around I used till now is to re-install all the packages again.
@vivek Please add details of the errors to the question (please include full error text, not a summary).
Hi @Richard, I have added exception details. Please check.
0

Make sure that all of your projects are using the same target framework, when this isn't done you can often get the type or namespace [name] could not be found warning.

To do this, right click each of the projects in the solution explorer > Properties > Application tab > Target Framework. They should all be the same or there will be incompatibilities between the references in your projects. Here's a question regarding this, hopefully this helps.

1 Comment

Thanks, but this is not a framework version issue. This is somewhere related to git and .sln or .csproj file reference handling.
0

The main reason is there no Autofac reference in packages.config file. When you see on the screen Restore packages message box this mean that nuget package manager is trying to install all the packages which are missing in the package folder. Try to do this step:

  • In Visual Studio Solution Explorer pick the project and via context menu pick Unload project
  • After project was unloaded via context menu pick Edit your project
  • Go to section group and find you Autofac Reference section
  • If HintPath doesnt looks like ..\packages\Autofac.4.1.1\lib\net45\Autofac.dll (Actual for 4.1.1 version) remove the Autofac reference Item
  • Save csproj file and reload project
  • Install Autofac via NuGet Package manager
  • Commit and push changes to git repository

Comments

0

Had the same problem with VS 2019. In ASP.NET, packages are updated via the .refresh files that appear in your bin folders. If these aren't checked into Git, they wouldn't be copied down to your cloned repro.

I added the .refresh files for all of my package dlls, made sure the versions and paths in the .refresh files were correct, and now everything updates as expected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.