how to resolve “Unable to find package” nuget error

送分小仙女□ 提交于 2019-12-23 18:24:26

问题


Working on creating a nuget pkg for a project (A.csproj) which depends on another project (B.csprojec) added as a project reference.
Here is the .nuspec ,

<?xml version="1.0"?>
<package >
  <metadata>
    <id>A.Client</id>
    <title>A.Client</title>
    <description>HttpClient and Models for calling the A Microservice.</description>
    <version>1.0.2</version>
    <authors></authors>
    <owners></owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <copyright>.</copyright>
    <tags></tags>
    <dependencies>
      <group targetFramework=".NETFramework4.5">
        <dependency id="Newtonsoft.Json" version="9.0.1" exclude="Build,Analyzers" />
        // <dependency id="B" version="1.0.0"/> tried this but same error
      </group>
      <group targetFramework=".NETStandard2.0">
        <dependency id="Newtonsoft.Json" version="9.0.1" exclude="Build,Analyzers" />
        // <dependency id="B" version="1.0.0"/> tried this but same error
      </group>
    </dependencies>
    <frameworkAssemblies>
      <frameworkAssembly assemblyName="System.Net.Http" targetFramework=".NETFramework4.5" />
    </frameworkAssemblies>
  </metadata>
  <files>
    <file src="bin\$configuration$\netstandard2.0\A.dll" target="lib\netstandard2.0" />
    <file src="bin\$configuration$\net45\A.dll" target="lib\net45" />
  </files>
</package>

I used

nuget pack A.nuspec -Properties configuration=debug

To generate the package. However when I tried to consume this package inside c.csprojc, I get the following error

Severity    Code    Description Project File    Line    Suppression State
Error   NU1101  Unable to find B. No packages exist with this id in source(s): Local Package source, Microsoft Visual Studio Offline Packages, nuget.org, Package source    

What did I miss ?


回答1:


I just did this and it went fine. In your Visual Studio, go to:

  1. Tools
  2. Nuget Package Manager
  3. General
  4. Click button "Clear All Nuget Cache(s)
  5. Package Resources and click "Update"
  6. Woolah! Error gone...



回答2:


The package source was offline !!

I installed VS2017 professional on my system and opened an existing project and found that multiple packages were missing. I tried everything I could, without looking at Package Source !!

I am writing this answer as I tried the below solutions but none of them worked :

  1. Clearing the cache
  2. Restoring or re-installing the packages
  3. Changing the targetFramework
  4. Updating the Nuget Package manager

Solution:

Step 01. Go to Package Manager Settings (Tools > Nuget Package Manager > Package Manager Settings)

Step 02. Check the Package Source(s). As you can see, the package source is here already downloaded SDK/nugets/packages. I don't know the reason but the online package source from nuget.org was missing from my system installation of Visual Studio.

Step 03. Install the nuget.org as package source and then 'Clear All Nuget Cache(s)' and then restore the packages. The error will go away.

Name: nuget.org ( or as you wish) Source: https://api.nuget.org/v3/index.json




回答3:


I resolved this by adding dependent file

<files>
    <file src="bin\$configuration$\netstandard2.0\a.dll" target="lib\netstandard2.0" />
    <file src="bin\$configuration$\net45\a.dll" target="lib\net45" />
    <file src="bin\$configuration$\netstandard2.0\b.dll" target="lib\netstandard2.0" />
    <file src="bin\$configuration$\net45\b.dll" target="lib\net45" />
  </files>

Also, don't forget to clean local cache nuget locals all –clean or change version.



来源:https://stackoverflow.com/questions/52376567/how-to-resolve-unable-to-find-package-nuget-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!