我正在尝试将 Nuget 包从 Telerik 的 Nuget 存储库提取到 Azure 构建管道中,但是,我所做的管道配置尝试似乎都不起作用。我要么收到一条错误,指出我的 nuget.config 格式不正确,要么在连接到存储库时收到 401 错误。
以下配置部分来自我的构建定义。我尝试过使用 NuGetCommand 以及 NuGetRestore:
- task: NuGetToolInstaller@1
inputs:
versionSpec: '5.0.2'
- task: NuGetAuthenticate@1
inputs:
nuGetServiceConnections: 'Telerik_v3'
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: './XXXXXXX/nuget.config'
#'$(System.DefaultWorkingDirectory)/XXXXXXX/NuGet.config'
externalFeedCredentials: 'Telerik_v3'
# - task: NuGetRestore@1
# inputs:
# solution: '**/*.sln'
# selectOrConfig: 'config'
# nugetConfigPath: './XXXXXXX/nuget.config'
这是我的 nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="Telerik_NuGet" value="https://nuget.telerik.com/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
这是我收到的错误:
NuGet.Protocol.Core.Types.FatalProtocolException:无法加载源的服务索引https://nuget.telerik.com/v3/index.json。 ---> System.Net.Http.HttpRequestException:响应状态代码不表示成功:401(未经授权)。
稍微调整配置,我收到此错误:
[错误]nuget 命令失败,退出代码(1) 和错误(NuGet.Configuration.NuGetConfigurationException: NuGet.Config 不是有效的 XML。路径: 'D: \Nuget empNuGet_966.config'。 ---> 系统.Xml.XmlException:解析 EntityName 时发生错误。第 10 行,位置 46。
我的构建任务基于 NuGetCommandv2 和 NuGetRestore v1 文档以及我在 Telerik 网站上找到的内容。
当我们想要使用像Telerik这样的私有nuget包时,我们需要在Nuget.config_
中指定凭据注意:
为了将此 NuGet 包的引用添加到您的项目中,首先需要将 Telerik 凭据添加到 Visual Studio。
示例:
dotnet nuget update source "Telerik" --source "https://nuget.telerik.com/v3/index.json" --configfile "nuget.config" --username '*************' --password '***********' --store-password-in-clear-text
在这里我找到了 Lance McCarthy 的一个参考文献 github