This project references NuGet package(s) that are missing on this computer.

By | October 1, 2015

The dreaded “NuGet Package Missing” error looks like this:

error : This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.

If you are on this page then there is a high chance that you have been stuck with the above error.

Package restore is a very good feature of NuGet, which is on by default. Simply put, if the packages are missing, NuGet will download them before the build starts.

If you are seeing above error then there is a high chance that you have moved projects around in your solution file.

FIX:
Open the .csproj of the project.
It will have this section:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>

Many people will advocate the sledgehammer approach of getting rid of this section. But this is wrong. You have to find the culprit. And it is: SolutionDir

Scroll up in the .csproj and you will see the place where this is getting its value:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\</SolutionDir>

Check if
“$(SolutionDir).nuget\NuGet.targets’))”
which actually translates to
“..\..\..\..\.nuget\NuGet.targets’))”
is pointing to the right directory. Most of the times when the projects are moved around, this is the place where messup happens.

So just put right value for SolutionDir (Maybe it should be ..\..\..\..\..\ instead of ..\..\..\..\)

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\</SolutionDir>

And your error should go away.

3 thoughts on “This project references NuGet package(s) that are missing on this computer.

    1. PankajK

      Few backslashes in the last two paragraphs were lost in the due to formatting issues. Can you check again?

      Reply
  1. Sami M Abbushi

    I ran into the same error on the build machine. My root problem – i.e. what threw the error – was fixing a build warning. The build warning was: “The ‘packages’ element is not declared.” This was from my packages.config file.
    I fixed this warning by adding the xml namespace attribute.
    Before:

    After my fix:

    This broke the build with the error: This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them….

    Once I took out the xml namespace (back to ), the build was successful.
    -Sami

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.