NuGet has problems with missing packages, how to restore?

前端 未结 5 1624
长情又很酷
长情又很酷 2021-02-05 04:52

When I try to compile my program I get the following error:

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


        
相关标签:
5条回答
  • 2021-02-05 05:03

    Use Package Manager Console in Visual Studio to run this command.

    1.This will restore all packages from solution

    nuget restore YourSolution.sln
    

    2.If you want to reinstall the packages to the same versions as were previously installed

    Update-Package -reinstall
    
    0 讨论(0)
  • 2021-02-05 05:03

    I ran into this issue when I tried to build my project on a computer where the packages-folder did not already exist in the solution root.

    When the project file was initially created, it seems VS2019 added the following into the project file:

    <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.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
    </Target>
    

    From what I understand those settings are deprecated nowadays, no idea why VS inserted it in the first place.

    Anyway, after removing those lines VS restored the packages and built the solution correctly again.

    0 讨论(0)
  • 2021-02-05 05:24

    Honestly, whoever developed the NuGet command for VS needs to go back to the drawing board. They totaly missed the fact that sometimes these DLL(s) and/or files get corrupt or deleted. a "NuGet Get-Packages -Force" option would really save their bacon. The only GAP I see is that VS and the Package console does not allow you to invoke a forced download from NuGet. Even clearing the cache via VS is useless.

    0 讨论(0)
  • 2021-02-05 05:24

    It's probably a good idea to clear the Nuget Cache by deleting the contents within this directory: C:\Users\{your_username}\AppData\Local\NuGet

    0 讨论(0)
  • 2021-02-05 05:25

    Well it's probably a bad way but I found that it works if I just delete the line

    http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />

    from the project.csproj , not sure if this is going to cause problems later on but it works for now.

    0 讨论(0)
提交回复
热议问题