如何解决“无法找到包";nuget错误 [英] how to resolve "Unable to find package" nuget error
问题描述
正在为依赖于作为项目参考添加的另一个项目 (B.csprojec) 的项目 (A.csproj) 创建 nuget pkg.
这是 .nuspec ,
<?xml version="1.0"?><包><元数据><id>A.Client</id><title>A.Client</title><description>调用A微服务的HttpClient和Models.</description><版本>1.0.2</版本><作者></作者><所有者></所有者><requireLicenseAcceptance>false</requireLicenseAcceptance><版权>.</版权><标签></标签><依赖关系><group targetFramework=".NETFramework4.5"><dependency id="Newtonsoft.Json" version="9.0.1" exclude="Build,Analyzers"/>//<依赖 id="B" 版本="1.0.0"/>试过这个但同样的错误</组><group targetFramework=".NETStandard2.0"><dependency id="Newtonsoft.Json" version="9.0.1" exclude="Build,Analyzers"/>//<依赖 id="B" 版本="1.0.0"/>试过这个但同样的错误</组></依赖关系><框架程序集><frameworkAssembly assemblyName="System.Net.Http" targetFramework=".NETFramework4.5"/></frameworkAssemblies></元数据><文件><file src="bin$configuration$
etstandard2.0A.dll" target="lib
etstandard2.0"/><file src="bin$configuration$
et45A.dll" target="lib
et45"/></文件></包>
我用过
nuget pack A.nuspec -Properties configuration=debug
生成包.但是,当我尝试在 c.csprojc 中使用此包时,出现以下错误
严重性代码描述项目文件行抑制状态错误 NU1101 无法找到 B.源中不存在具有此 ID 的包:本地包源、Microsoft Visual Studio 脱机包、nuget.org、包源
我错过了什么?
包源离线!!
我在我的系统上安装了VS2017专业版并打开了一个现有的项目,发现缺少多个包.我尽我所能,没有看包源!!
我正在写这个答案,因为我尝试了以下解决方案,但它们都没有奏效:
- 清除缓存
- 恢复或重新安装软件包
- 更改目标框架
- 更新 Nuget 包管理器
<小时>
解决方案:
步骤 01. 转到 包管理器设置(工具 > Nuget 包管理器 > 包管理器设置)
步骤 02.检查包源.可以看到,包源在这里已经下载了SDK/nugets/packages.我不知道原因,但我的 Visual Studio 系统安装中缺少来自 nuget.org 的在线包源.
步骤 03. 安装 nuget.org 作为包源,然后清除所有 Nuget 缓存",然后恢复包.错误会消失.
名称:nuget.org(或如您所愿)来源:
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$
etstandard2.0A.dll" target="lib
etstandard2.0" />
<file src="bin$configuration$
et45A.dll" target="lib
et45" />
</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 ?
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 :
- Clearing the cache
- Restoring or re-installing the packages
- Changing the targetFramework
- 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
这篇关于如何解决“无法找到包";nuget错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!