Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing from Nuget adds reference to bin directory

I'm installing the AvsAn (2.1.0) package using the Nuget Package manager. I am expecting the reference path to be to the packages directory, something like:

C:\app\packages\AvsAn.dll

But a reference to the bin directory is added:

C:\app\NameSpace\bin\AvsAn.dll

Confusingly this is happening for some packages but not for others (i.e the reference path is to the packages folder, as expected)

What I've tried

  • Uninstalling and reinstalling the package
  • Googling for something similar (I've been unable to find anything)
like image 455
Vinyl Warmth Avatar asked May 09 '16 09:05

Vinyl Warmth


People also ask

What happens when you install a NuGet package?

NuGet creates a subfolder for each package identifier, then creates subfolders for each installed version of the package. NuGet installs package dependencies as required. This process might update package versions in the process, as described in Dependency Resolution.

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).

What is NuGet package reference?

PackageReference (or "package references in project files") | (NuGet 4.0+) Maintains a list of a project's top-level dependencies directly within the project file, so no separate file is needed.


1 Answers

We found that different projects within the same solution were using different versions from one another. Additionally, a single project might have a version listed in the <Reference> element from the version listed in the HintPath.

We simply went through each .csproj file and manually edited them to get everything in sync.

  • Find the line that begins with <Reference that includes the information for the dll in question.
  • This line should indicate a version. For example: <Reference Include="SomeAssembly, Version=4.0.54">. There may be some additional text after this such as Culture and/or PublicKey, etc. We're just interested in the Version attribute.
  • Make a note of this Version.
  • Now check the <HintPath>element within <Reference, it will contain the path to that dll that VS will expect (where VS will look first).
  • This path will also contain a version ..\packages\SomePackage.4.0.56\lib\net45\SomeAssembly.dll (for example - in our case it was Service Stack packages). While this isn't technically a version (it's just a path to a file on your system), it will typically correspond to the version of the dll.
  • You need to make sure that these two things are in sync - that the path listed actually exists and that it leads to the expected dll.

In our case we were moving from ServiceStack 4.0.54 to 4.0.56. Some of the Include references were to 4.0.56 while the path still pointed to the 4.0.54 version. Because the hint path did not point to the expected dll VS looked elsewhere and it found what it believed to be an acceptable match in the project's \bin\debug directory. This was not the correct version.

It will be up to your specific situation as to which to change and to what.

This was most likely caused by poor merges.


Additionally we cleared out the \bin and \packages directories underneath the project folder. Reloaded solution and let Nuget restore. This is just to clear things out so that Nuget can pull down just the packages, and their versions, that it needs. And it prevents VS from using wrong versions that may be located in the project's \bin directory. Both are safe to delete. The \packages folder will be recreated and populated via Nuget restor, and the \bin directory will be recreated and populated upon the next build of the solution.

like image 112
David Martin Avatar answered Sep 20 '22 23:09

David Martin