【问题标题】:Dotnet build for private nuget packages fails with "Unable to load the service index for source https://privatenuget.org/F/packages/api/v3/index.json"私有 nuget 包的 Dotnet 构建失败,并显示“无法加载源 https://privatenuget.org/F/packages/api/v3/index.json 的服务索引”
【发布时间】:2022-11-01 14:54:28
【问题描述】:

我的解决方案中有私有 nuget repo 包,当我恢复它们以在 Visual Studio 中构建我的应用程序时,出现以下错误

Severity    Code    Description Project File    Line    Suppression State
Error   NU1301  Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. MyPrivate.Project.Repository    C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj  1   

以流行的分辨率

Nuget connection attempt failed "Unable to load the service index for source" 我尝试删除 %AppData%\Roaming\NuGet\NuGet.Config 并重新启动对我不起作用的 VS。

我的 Nuget.Config 看起来像这样。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="MyGet.orgV3" value="https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageManagement>
    <add key="format" value="1" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

甚至尝试过dotnet restore --interactive

但徒劳无功

dotnet restore --interactive
  Determining projects to restore...
C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj : error NU1301: Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. [C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj]

存储库需要密码/AzureAAD 身份才能访问,并且我已使用可以访问私有存储库的帐户登录到 Visual Studio/终端。我认为这以某种方式阻止了服务索引的加载,但我有一个实现它的障碍。

访问私有包仓库:

我的包源如下所示:

【问题讨论】:

    标签: asp.net .net visual-studio visual-studio-2022 nuget-package-restore


    【解决方案1】:

    我有一个肮脏的解决方案。

    我决定在 Nuget.Config 中使用私有 nuget repo 用户名和密码(至少在本地)。 我将 Nuget.Config 更改为:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <packageSources>
            <add key="MyGet" value="https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json" />
        </packageSources>
        <packageSourceCredentials>
            <MyGet>
                <add key="Username" value="myusername" />
                <add key="ClearTextPassword" value="mysecretpassword" />
            </MyGet>
        </packageSourceCredentials>
        <packageRestore>
            <add key="enabled" value="True" />
            <add key="automatic" value="True" />
        </packageRestore>
        <packageManagement>
            <add key="format" value="1" />
            <add key="disabled" value="False" />
        </packageManagement>
    </configuration>
    

    我通过运行从 NuGet 文件夹中删除了 NuGet.Config

    然后,从 VS Developer PowerShell 终端(因为它不能与 UI 构建选项卡一起使用)我运行 dotnet restore 并恢复了包。

    我正在寻找更好的答案以避免明文密码。

    【讨论】:

      【解决方案2】:

      这是我正在寻找的正确解决方案: 检查 NuGet 包管理器设置中的包还原选项,如下所示:

      它又开始建造了!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-22
        • 1970-01-01
        相关资源
        最近更新 更多