3

I am using NuGet to manage dependencies.

I created a fresh Git clone of my solution, and noticed assembly reference problems.

I have Enabled Package Restore and checked settings as suggested here, but I still have these yellow caution icons on various assembly references:

references

For example, I had previously added AutoMapper through NuGet, so why is it broken here, and why isn't it showing in my packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="bootstrap" version="3.0.0" targetFramework="net45" />
  <package id="EntityFramework" version="6.1.1" targetFramework="net45" />
  <package id="jQuery" version="1.10.2" targetFramework="net45" />
  <package id="Modernizr" version="2.6.2" targetFramework="net45" />
</packages>
Community
  • 1
  • 1
J86
  • 14,345
  • 47
  • 130
  • 228

4 Answers4

1

This usually means that the reference you have in your project refers to an assembly which cannot be found on disk. To correct this problem the most direct solution is to note which references exist, remove them, and then re-add them. Since you are using NuGet to manage dependencies your job is much easier, you simply need to:

  1. Remove all NuGet Packages (using "Package Manager")
  2. Remove any lingering broken assembly references throughout your solution
  3. Re-Add NuGet Packages to all projects which need them (again using Package Manager)

Based on your description, it sounds as though some projects did not have NuGet packages added to them, and perhaps the assemblies were 'cross referenced' by a developer from the NuGet packages folder. This is a mistake. Instead the NuGet packages must be added to all projects which depend on the packages. (For example, you should never find yourself manually adding an assembly reference to AutoMapper, ever, because it is managed by NuGet for you.)

Sometimes there is a bug where these appear prior to a nuget fetch, and selecting the reference node in Solution Explorer will cause the overlay glyph (yellow caution symbol) to remove itself (meaning the reference was resolved post-load, usually by 'package restore'.)

This is most often caused by project authors creating incorrect/direct references to assemblies in non-standard locations, thus a package restore will not resolve the reference issues, and the references typically break after a package update.

HTH

Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
0

I manually went and removed all references that had the yellow mark next to them and then added them back one by one. This way, they started showing up in packages.config too.

I think the reason they weren't showing in packages.config previously was because I turned on the [Restore nuget packages] option much later in development. Had I done this as soon as I started my porject, I believe they would have shown up in packages.config.

PS. I used the search on nuget's website to find out if the package was available on nuget, or if it was a framework assembly.

J86
  • 14,345
  • 47
  • 130
  • 228
  • 1
    The restore option doesn't affect `packages.config`, and never has. It is more likely the cause for that issue is related to check-in/merge mistakes (or adding references to nuget packages of OTHER projects, rather than using nuget package manager to manage references, which is the correct way to manage references when using nuget.) – Shaun Wilson Mar 06 '15 at 23:17
  • 1
    Additionally, you can use the "Package Manager" in Visual Studio (not the the Console, but the full UI) to search nuget.org packages. You can also use the "Reference Manager" dialog and select the "Assemblies->Framework" node, and the "Search Box" in the top right of the dialog to look up framework-supplied assemblies. Properly configured packages should already identify their framework dependencies. Thus, it's usually faster to remove all references and then add dependencies from nuget rather than hunt down all the framework references on your own. – Shaun Wilson Mar 06 '15 at 23:20
0

You need to reinstall all packages in a project using:

Update-Package -ProjectName MyProject -Reinstall
Nitin Badole
  • 495
  • 6
  • 12
0

In Package Manager Console, select your Default Project

Then

Update-Package -reinstall
Kirsten
  • 15,730
  • 41
  • 179
  • 318