Error using nuget in VS2012 "missing packages"

44,095

Solution 1

As Dan was alluding to, if your solution has a .nuget folder (from enabling package restore), then nuget 2.7's automatic package restore feature is disabled, as per http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore.

If automatic package restore is disabled, then any package that installs a project target files will cause your build to fail until you manually restore that package in your solution, as described by http://blogs.msdn.com/b/dotnet/archive/2013/06/12/nuget-package-restore-issues.aspx. (Note that the workarounds described in the link are out-dated now that nuget 2.7 automatic package restore is available.)

So, if both these things are true, then delete the NuGet.targets file in the .nuget folder, and Nuget will then restore the missing package before invoking MSBuild. You can delete nuget.exe in the .nuget folder as well, as it will no longer be used.

Solution 2

Please follow below mentioned steps:

Step 1: Please enable Nuget Package Restore by right clicking on solution [as mentioned in below screenshot]

Enable Nuget Package Restore

Step 2: [Follow this if the issue / error is not resolved by following step 1] Still if you face the issue, please open .csproj file in notepad and check for the package path which might look like

Package Path

So your solutions directory structure will be like:

\SolutionDirectory\

Package Directory:

\SolutionDirectory\packages

Project Directory:

\SolutionDirectory\ProjectName\ProjectName.csproj

Please open this .csproj [in which you're getting error] in notepad and search for packages path and update it to its relevant path.

For e.g. my .csproj contained, if .csproj file contains ..\..\packages then update that path with ..\packages

Solution 3

The answers are very helpful for me to find the solution. Since the resolution to my specific issue requires one more step, I report it here in case it is helpful to others. The error I was getting:

Error   117 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 ..\..\Windows Phone 8\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets.

I followed the answers and deleted all the suggested things, but the error still kept showing up. I finally got rid of it by deleting the following line in the .csproj:

<Error Condition="!Exists(...

Solution 4

  1. Delete NuGet
  2. Remove with Notepad .targets that depending NuGet from project file
  3. Install latest version of NuGet
  4. Restart Visual Studio and reopen project/solution.
  5. If you want you can add new .nuget files with latest version of NuGet

Solution 5

Open csproj file in notepad and remove Error Condition elements from here (or make these conditions work):

<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>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
    <Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.101.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.101.0\build\net45\System.Data.SQLite.Core.targets'))" />
  </Target>
Share:
44,095
John S
Author by

John S

Been around since the days of Business Basic and the 6502. Currently working mostly in the Microsoft stack, C#, SQL, etc.. Also work with SCSS, CSS, JQuery, Javascript. Currently a Software Engineer that likes to keep up on some aspects of the IT side of things so that I can do a better job writing my software. Always striving to understand the whole problem domain not just the algorithm.

Updated on November 25, 2020

Comments

  • John S
    John S over 3 years

    When I build my project from within VS2012 I get the following error message

    This project references NuGet package(s) that are missing on this computer. 
    Enable NuGet Package Restore to download them. 
    

    I have the nuget options set for NuGet to download missing packages.

    picture of nugget options

    Yet I still get the error. I have nugget 2.7 installed. With VS2012 update 3