NuGet Packages are missing

301,823

Solution 1

I had the same error (missing exactly the same package) today. I also created a MVC + Web API project.

It happened because I moved the app files (including the .csproj) file to another location. I manually updated the .sln file but all packages dependencies are now (Visual Studio 2015) stored in .csproj file.

Editing the .csproj file and correcting the relative path to the solution folder (which contains the packages folder) solved the problem for me.

Solution 2

I solved my issue by removing this code from .csproj file:

<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'))" />
</Target>

Solution 3

BEWARE - this updates packages for the entire solution not just the project.

If you have one more missing nuget package that giving your error while building your solution use following command using Nuget Command Console from Tools > Nuget Package Manager > Package Manager Console. It will reinstall your all current packages.

Update-Package –reinstall

Update:

You can pass specific project name as a parameter.

Update-Package –reinstall -ProjectName SampleApp

Solution 4

I had this exact frustrating message. What finally worked for me was deleting all files and folders inside /packages and letting VS re-fetch everything the next build.

Solution 5

this way solved my error : To open .csproj file for update in Visual Studio 2015+ Solution Explorer:

Right-click project name -> Unload Project

Right-click project name -> Edit .csproj

Remove the following lines :

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
    <Error Condition="!Exists('packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
  </Target>

Right-click project name -> Reload Project

Finally Build your solution.

Share:
301,823
Ques Tion
Author by

Ques Tion

Updated on January 29, 2022

Comments

  • Ques Tion
    Ques Tion over 2 years

    I searched this problem but none of the solutions worked. I have Visual Studio Professional 2015 installed and I am using TFS. My NuGet version is 3.1.6. This problem is happening only in my C# Web API/MVC project.

    I am getting the below error:

    This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props

    1. I do not have .nuget folder in my solutions.
    2. I have a packages folder in the solution and when I delete it, it seems like NuGet does rebuild the dependencies but the project still has the above error.
    3. I tried removing the project from TFS and it didn't fix it.
    4. Along with the above error, all the references in the project have yellow warning signs and say they are missing.
    5. When I checked the NuGet Package Manager for the project, everything that is "missing" has a green tick next to it, including Microsoft.Net.Compilers.
    6. I tried adding a new Web API/MVC project and it faced a similar problem where most references such as Owin were "missing" with the yellow warning sign.
  • Justin Wignall
    Justin Wignall over 8 years
    Copying the Microsoft.Net.Compilers... folder from the old packages folder to the new packages location after a move if it is missing may be a final step required.
  • Vitor Canova
    Vitor Canova over 8 years
    I did a right click on the Solution and Restore Nuget Packages.
  • Patrick Borkowicz
    Patrick Borkowicz over 8 years
    This worked for me. The error popped up after for me after pushing changes through git on one system and pulling them on another. Maybe my .gitignore is not properly configured for nuget packages.
  • SO User
    SO User about 8 years
    Beware ... this updates packages for the entire solution not just the project.
  • ISAE
    ISAE about 8 years
    what did work for me in the end was to edit only the line at the end of the file, but not at the top
  • SpoiledTechie.com
    SpoiledTechie.com about 8 years
    I just removed that ONE package from my computer and it worked.
  • Levi Fuller
    Levi Fuller about 8 years
    Accepted answer would not work since I am referencing the project in multiple separate solutions. This was the only fix. Commented it out and it worked like a a charm.
  • Ziggler
    Ziggler about 8 years
    I donot have any Restore Nuget Package when I right click on solution.... I am using VS 2013..
  • Andrew Jens
    Andrew Jens over 7 years
    I also got the error when physically moving a project to a different location in the Visual Studio solution. None of the solutions on this page worked, so I made a copy of the project (on the file system) and completely removed all reference to the original project in VS. I then recreated the project and copied the bits and pieces into it (from the copy I made). Laborious, but it worked.
  • Nick Alexander
    Nick Alexander over 7 years
    This worked for me. NuGet kept complaining about missing packages, but Visual Studio would not auto-resolve. It took a couple minutes to run completely, but this command fixed my problem.
  • Maarten Kieft
    Maarten Kieft over 7 years
    I also removed these lines, but I'm more wondering, why are those lines there. Its not than my code won't run. Also why are those nugets so special that they must be included? Why was a normal broken reference not enough??
  • HeyZiko
    HeyZiko over 7 years
    I could be wrong, but I believe this is "swatting the fly with the hammer". If, for whatever reason, the published location loses any other required nuget package, it will not error, giving you a false positive (i.e. deployment succeeds, but system fails). Not a fan, but I'm not going to downvote it because there are aspects of nuget I'm still not familiar with.
  • Ryan Peters
    Ryan Peters about 7 years
    This also worked for me. Odd that the error message was hard-coded in the proj file itself ...
  • Tom McDonald
    Tom McDonald about 7 years
    Confirmed this issue still exists in VS 2017. I migrated a project from visual studio 2015 to 2017 and got this error message upon first compile in 2017. This fixed the bug.
  • Nirman
    Nirman about 7 years
    I also had the same issue after moving project from one location to another. Fixing path of the packages in the ".csproj" file fixed the issue.
  • Nicow
    Nicow about 7 years
    Why delete functionality, risk your project breaking etc by doing this? As @HeyZiko points out this can lead to problems later on. I could just do what the error states "Enable package restore". See my answer somewhere on this page...
  • Jain Prince
    Jain Prince almost 7 years
    Thanks!! I too faced similar situation, and 'Enable NuGet Package Restore' worked.
  • Miłosz Wieczorek
    Miłosz Wieczorek almost 7 years
    Instead of doing it manually, I suggest doing it via Package Manager console: 'update-package -ProjectName {ProjectName} -Reinstall' . This works like a charm :)
  • Miłosz Wieczorek
    Miłosz Wieczorek almost 7 years
    You can add -ProjectName parameter to make it only for specific project, not entire solution.
  • Dalibor
    Dalibor almost 7 years
    It didn't wok for me, it says "All packages are already installed and there is nothing to restore."
  • Sachin
    Sachin almost 7 years
    I think this is not a good answer, it is something like if any testcase is not passing then comment that and you task is done. But that is not a way.. You must have find the root cause and resolve it, rather than commenting or removing such code..
  • Francisco d'Anconia
    Francisco d'Anconia almost 7 years
    @MiłoszWieczorek I tried running the command in Package Manager Console and it did not solve the issue. It reloaded all packages, but the references are still not found.
  • alehro
    alehro almost 7 years
    This answer didn't help at once but given me right direction. Additionally to <Target Name="EnsureNuGetPackageBuildImports"... there were some excessive <Import Project... nodes. So, general approach is to read your project file xml and get rid of everything not making sense.
  • Sebastian Schumann
    Sebastian Schumann over 6 years
    I've exactly that problem using VS2017, .Net4.7 and a unit testing project. That project is added to multiple solutions. The automatic restore works but to the wrong place. Replace with $(SolutionDir) work but update failes. I asked that here. Do you have any solution found?
  • Dan Csharpster
    Dan Csharpster over 6 years
    I had this problem because my file path was too long for package Microsoft.CodeDom.Providers.DotNetCompilerPlatform. My fix was to move the entire solution closer to the root C:\. Error message: Install-Package : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters
  • CodeHxr
    CodeHxr over 6 years
    This may be "swatting a fly with a hammer", but in my case, my project had ZERO nuget packages (one other project in the solution did, though, if that makes a difference, but that project compiled fine) and the options to "Enable package restore" were, in fact, checked.
  • codecypher
    codecypher over 6 years
    Rather than delete this entry in .csproj, I edited it to correct the path to the packages folder and it worked.
  • Zephryl
    Zephryl over 6 years
    Just FYI, I upgraded the compiler via nuget and it left these pointed to the old version. So, my fix was to leave the paths along and update the version numbers. The correct paths were at the top in <Import /> tags
  • Richard Moore
    Richard Moore about 6 years
    Didn't read Rashmi's comment about it updating packages for the entire solution until it was too late. BEWARE
  • rollsch
    rollsch about 6 years
    VS2017 crashed half way through this and it broke everything
  • Umair Anwaar
    Umair Anwaar over 5 years
    I just restore whole nudget packages multiple times but problem resolved by removing these line of hard-coded error.
  • Protector one
    Protector one over 5 years
    But why where these wrong in the first place? Bug in Visual Studio?
  • Matheus Miranda
    Matheus Miranda over 5 years
    Saved my day. Thank you
  • willyMon
    willyMon about 5 years
    After fixing manually the paths in csproj I removed the section EnsureNuGetPackageBuildImports and it worked perfectly. thanks
  • ZF007
    ZF007 about 5 years
    You are reporting the traceback error and no answer to the question how its solved (regardless the hint of MS in that error-log). You posted information and the real answer are posted multiple times. Therefore unfortunately low quality answer and thus no answer.
  • AceMark
    AceMark about 5 years
    also had to make sure that it restores to the right package. check the .csproj using note/Edit *.csproj for the location of the packages folder
  • CyberNinja
    CyberNinja almost 5 years
    I did this, but i only remove the dot.compiler reference, which we dont really need in production neither on the test env.
  • Károly Ozsvárt
    Károly Ozsvárt almost 5 years
    I had a problem where I moved the project files to the level of the .sln file, and I had to change the "..\packages\etc" references to ".\packages\etc", so it wouldn't climb up one directory.
  • Nick
    Nick over 4 years
    I removed all the nuget packages from the packages folder, and then tried redownloading all packages at build received a build error. I then just had to reinstall the nuget.org/packages/… package and everything worked perfectly
  • sgrysoft
    sgrysoft over 4 years
    No edit is need it, edit the csprog is the evil, is a better idea test to clear the cache of the packages
  • Asiri Dissanayaka
    Asiri Dissanayaka almost 4 years
    In my case I moved .sln and changed paths to .csproj files, then got this error. Correcting the paths in .csprojs worked for me.
  • Andrew Morton
    Andrew Morton over 3 years
    This also applies when there is a rogue error condition referring to 3.5.0 when it has been updated to 3.7.0.
  • ssmith
    ssmith over 3 years
    Just says "No package updates are available from the current package source for project " and doesn't do anything in my case.
  • ssmith
    ssmith over 3 years
    Worked for me. A bit overkill but other options didn't fix the issue.
  • 4e 69 63 6b
    4e 69 63 6b almost 3 years
    I had this exact same issue - .NET 4.7.2 csproj file was moved inside of a "src" subfolder so the references to "packages" were off by one directory. This also corrected a separate issue that prevented me from installing various NuGet packages. Specifically Autofac v6.2.0, which reported "Failed to add reference. The package 'System.Numerics.Vectors' tried to add a framework reference to 'System.Numerics' which was not found in the GAC. This is possibly a bug in the package."
  • CervEd
    CervEd over 2 years
    Those conditions are checking that packages exists in two places. (a bit odd, one is enough). A better alternative to deleting them is to fix the path to point to the actual packages folder. It's relative. Your package folder is likely ..\..\packages or ..\..\..\packages or similar.
  • Eric Aya
    Eric Aya over 2 years