Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The package could not be found in C:\Users\username\.nuget\packages\. Run a NuGet package restore to download the package

Tags:

nuget

The package CacheManager.Core with version 1.0.1 could not be found in C:\Users\username\.nuget\packages\. Run a NuGet package restore to download the package.

but my project is in D: drive. all of other packages are fine except error for this package. here is snapshoot of packages.config

<packages> <package id="CacheManager.Core" version="1.0.1" targetFramework="net462" /> <package id="Castle.Core" version="3.3.3" targetFramework="net462" /> <package id="Castle.Windsor" version="3.3.0" targetFramework="net462" />...

Actually, the packages are in both mentioned C:\Users\username.nuget\packages\ and in project file location

like image 392
user9665486 Avatar asked Oct 21 '18 22:10

user9665486


People also ask

How do I force a NuGet package to restore?

Restore packages manually using Visual StudioEnable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

How do I fix a NuGet package error?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

Why is my NuGet package missing from my project?

This project references NuGet package (s) that are missing on this computer. Use NuGet Package Restore to download them. The missing file is {name}. This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.

How do I enable package restore in NuGet?

If you're using Visual Studio, first enable package restore as follows. Otherwise continue to the sections that follow. Select the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore.

Why am I getting a NuGet installation error when trying to build?

This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.

Why is my assets file not found in NuGet?

Assets file '<path>\project.assets.json' not found. Run a NuGet package restore to generate this file. The project.assets.json file maintains a project's dependency graph when using the PackageReference management format, which is used to make sure that all necessary packages are installed on the computer.


2 Answers

In our cases following files were created:

obj/LcWebServerExtension.csproj.nuget.cache
obj/LcWebServerExtension.csproj.nuget.g.props
obj/LcWebServerExtension.csproj.nuget.g.targets
obj/project.assets.json

The .g.props file just listed the C:\Users\... directory, no other of the properly configured directories.

You need two steps to solve the problem:

  1. Set back ToolsVersion of .csproj file from "15" to "12". Right appearance:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Import ...
    
  2. Manually delete obj/ folder, then rebuild

like image 157
jifb Avatar answered Oct 17 '22 09:10

jifb


I got the same error when building a project in vs2019 although the package name and user profile were differnt from yours.

It happened to me that I had worked on a project under a profile userA, which was deleted later on. Therefore, it popped up an error when I built the project under a profile userB:

"The package EntityFramework with version 6.1.3 could not be found in C:\Users\userA\.nuget\packages. Run a NuGet package restore to download the package."

I tried to resolve the issue in vain by restoring the packages and revising the nuget config. Finally, I deleted the all files generated by VS2019, which were hidden by .gitignore file. And then the issue was resolved after retoring the packages.

I think the error was caused by .dtbcache file located in .vs folder: $\Solution\.vs\ProjectName\DesignTimeBuild\.dtbcache.v2

This file stores the nuget package information. It was outdated after I switched to another user profile as the nuget package path was not updated.

At Stack Overflow there is a disscusion about .dtbcache file: What does the .dtbcache file do?

And here is a similiar issue on GitHub: https://github.com/dotnet/project-system/issues/5418

The question was posted almost 2 years ago and it might be already resolved. Yet I am answering in case someone else comes across this issue. Hope my comment would be helpful.

like image 25
Jeff Avatar answered Oct 17 '22 08:10

Jeff