【发布时间】:2022-04-01 22:28:26
【问题描述】:
正在为依赖于作为项目参考添加的另一个项目 (B.csprojec) 的项目 (A.csproj) 创建 nuget pkg。
这是 .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>
我用过
nuget pack A.nuspec -Properties configuration=debug
生成包。但是,当我尝试在 c.csprojc 中使用此包时,出现以下错误
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
我错过了什么?
【问题讨论】:
-
您是否构建了包 B?该错误表明包 B 未构建或无法从包含包 A 的目录中获得。您使用的
nuget pack命令仅提及 A.nuspec。 -
a 和 b.csproj 在同一个解决方案中,a 引用 b 作为项目,而不是包。
-
您在使用
nuget pack时尝试过-IncludeReferencedProjects选项吗? -
在Tools -> Nuget package Manager -> package manager settings (Package source tab)下设置包源地址:api.nuget.org/v3/index.json