致力于为依赖于作为项目参考添加的另一个项目 (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>
Run Code Online (Sandbox Code Playgroud)
我用了
nuget pack A.nuspec -Properties configuration=debug
Run Code Online (Sandbox Code Playgroud)
生成包。但是,当我尝试在 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
Run Code Online (Sandbox Code Playgroud)
我错过了什么 ?
jai*_*ish 79
包源下线!!
我在我的系统上安装了 VS2017 Professional 并打开一个现有项目,发现缺少多个包。我尽我所能,没有查看包源!
我正在写这个答案,因为我尝试了以下解决方案,但都没有奏效:
解决方案:
步骤 01。转到包管理器设置(工具 > Nuget 包管理器 > 包管理器设置)

步骤 02。检查包源。可以看到,包源在这里已经下载了 SDK/nugets/packages。我不知道原因,但是我的 Visual Studio 系统安装中缺少来自 nuget.org 的在线包源。
步骤 03. 安装 nuget.org 作为包源,然后“清除所有 Nuget 缓存”,然后恢复包。错误将消失。
名称:nuget.org(或如您所愿)来源:https ://api.nuget.org/v3/index.json
sot*_*tto 17
对我来说,%appdata%\NuGet\NuGet.Config仅包含
<activePackageSource>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</activePackageSource>
Run Code Online (Sandbox Code Playgroud)
做完之后
nuget sources add -Name "NuGet official package source" -Source "https://api.nuget.org/v3/index.json"
Run Code Online (Sandbox Code Playgroud)
这是添加的
<packageSources>
<add key="https://www.nuget.org/api/v2/" value="https://www.nuget.org/api/v2/" />
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Run Code Online (Sandbox Code Playgroud)
后来发现了包裹。
JBS*_*rro 10
我想补充一点,在 Github Actions 中,默认情况下不会查询 nuget.org 存储库。相反,GitHub 默认使用缓存的包存储库,并且您引用的包可能不在该缓存中,而是在nuget.org 上(我有System.CommandLine)。
您可以通过将nuget.config包含以下内容的文件添加到根目录来解决此问题
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud)
示例 github_action.yml 文件
name: .NET
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0
- name: Clean
run: dotnet clean && dotnet nuget locals all --clear
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
Run Code Online (Sandbox Code Playgroud)
我只是这样做了,一切顺利。在您的 Visual Studio 中,转到:
我有类似的问题。它找不到这些软件包,因为它正在寻找离线存储在我的计算机中而不是在线存储的软件包。Visual Studio NuGet 设置屏幕没有显示此内容,但错误消息显示了。我对离线包不感兴趣,所以要解决它(Windows):
首先转到 Visual Studio 2019 中的“工具”>“Nuget 包管理器”>“包管理器设置”>“包源”并添加:https://api.nuget.org/v3/index.json(如果尚未存在),请提供名称 nuget.org。这样做后我的错误仍然存在,因此接下来的步骤。
按开始并输入 %appdata% 将您带到 C:/Users/[用户名]/AppData/Roaming。导航到 NuGet 目录并打开 NuGet.Config。
所有包源都显示在此处,即使它们未出现在 Visual Studio 包管理器设置中也是如此。
修改 PackageSources 部分以删除不需要的源。就我而言,我不需要离线源,所以我只剩下:
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Run Code Online (Sandbox Code Playgroud)
这为我解决了这个问题。
我通过添加依赖文件解决了这个问题
\n\n<files>\n <file src="bin\\$configuration$\\netstandard2.0\\a.dll" target="lib\\netstandard2.0" />\n <file src="bin\\$configuration$\\net45\\a.dll" target="lib\\net45" />\n <file src="bin\\$configuration$\\netstandard2.0\\b.dll" target="lib\\netstandard2.0" />\n <file src="bin\\$configuration$\\net45\\b.dll" target="lib\\net45" />\n </files>\nRun Code Online (Sandbox Code Playgroud)\n\n另外,不要忘记清理本地缓存nuget locals all \xe2\x80\x93clean或更改版本。
| 归档时间: |
|
| 查看次数: |
82587 次 |
| 最近记录: |