azure-devops - Azure DevOps Server dotnet Restore 无法访问源

标签 azure-devops

我需要将 .NET Core 构建管道任务与 restore 命令结合使用。目标是恢复解决方案的包引用 (*.nupkg)。我有两个包源:

  • nuget.org
  • ADS 上的私有(private)工件源 (MyFeed)

我的解决方案中的一些项目引用了来自MyFeed的包,并且需要在构建之前在代理上恢复。

enter image description here


错误

当任务尝试从我的私有(private) feed MyFeed 下载软件包时失败:(不幸的是,输出是德语,所以我将错误消息放入谷歌翻译器中,希望一切顺利)

C:\Program Files\dotnet\sdk\3.1.402\NuGet.targets(128,5): error: Error getting information about "ext.lib.MyPackage" from the remote source "https://MyUrl.de/Collection/_packaging/38df75fe-122d-57f9-af47-de3a09231f5e/nuget/v3/flat2/ext.lib .MyPackage / index.json ".
C:\Program Files\dotnet\sdk\3.1.402\NuGet.targets (128,5): error: No login information is available in the security package. [D:\AzureDevOpsData\Agents\MyAgent\_work\2\s\MySolution.sln]

我做了什么?

使用 NuGet 任务

我尝试使用 NuGet 任务重现该行为,但通过此任务一切正常。此任务可以访问我的私有(private)提要MyFeed重要提示:NuGet 任务无法替代使用,我们需要使用 .NET Core 任务

Windows 凭据管理器

我将 Feed 添加到代理上 Visual Studio 2019 中的包管理器中,并输入代理用户的凭据。由于将 2 个条目添加到我的 Windows 凭据管理器中。

enter image description here

此更改不能解决问题,错误消息是相同的。


编辑 1:将身份验证添加到 NuGet.Config

我尝试将身份验证添加到我的 NuGet.Config 中。这种方法有很多变数,我尝试列出我尝试过的所有品种。

NuGet.Config 路径

dotnet Restore 任务提供 NuGet 配置选项:

enter image description here

  1. 选项:我与 %APPDATA%\NuGet\NuGet.Config 关联(但我不确定)
  2. 选项:是存储库的 NuGet.Config 路径

因此,对于所有运行,我总是尝试这两个选项!

  1. 运行:用户名域密码(已加密)❌
  2. 运行:用户名PAT(ClearTextPassword)❌
  3. 运行:Domain\Username with PAT (ClearTextPassword) ❌
  4. 运行:用户名域密码(ClearTextPassword)❌
  5. 运行:Domain\UsernameDomain Passwort (ClearTextPassword) ❌

所有运行的 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" />
    <add key="MyFeed" value="https://MyFeedUrl/nuget/v3/index.json" />
  </packageSources>
  <config>
    <add key="http_proxy" value="http://www-MyProxy.de:3000" />
    <add key="https_proxy" value="http://www-MyProxy.de:3000" />
  </config>
  <packageSourceCredentials>
    <MyFeed>
        <add key="Username" value="$MyRunUser" />
        <add key="ClearTextPassword" value="$MyRunKey" /> <- ClearTextPassword OR Password
        <add key="ValidAuthenticationTypes" value="basic" />
      </MyFeed>
  </packageSourceCredentials>
</configuration>

临时 NuGet.Config

无论我做什么,dotnet 任务始终会创建并使用临时 NuGet.Config。从 system.deubg = true 日志我可以得到:

##[debug]Getting credentials for local feeds
SYSTEMVSSCONNECTION exists true
##[debug]SYSTEMVSSCONNECTION exists true
##[debug]Got auth token
##[debug]externalEndpoints=null
##[debug]Setting up sources
##[debug]selectOrConfig=config
##[debug]nugetConfigPath=D:\AzureDevOpsData\Agents\MyAgent\_work\18\s\MyNuGet.Config
##[debug]check path : D:\AzureDevOpsData\Agents\MyAgent\_work\18\s\MyNuGet.Config
##[debug]nugetConfigPath=D:\AzureDevOpsData\Agents\MyAgent\_work\18\s\MyNuGet.Config
##[debug]Absolute path for pathSegments: D:\AzureDevOpsData\Agents\MyAgent\_work\18\s\MyNuGet.Config = D:\AzureDevOpsData\Agents\MyAgent\_work\18\s\MyNuGet.Config
##[debug]build.sourcesDirectory=D:\AzureDevOpsData\Agents\MyAgent\_work\18\s
##[debug]Absolute path for pathSegments: D:\AzureDevOpsData\Agents\MyAgent\_work\18\s = D:\AzureDevOpsData\Agents\MyAgent\_work\18\s
##[debug]nugetConfigPathpath supplied :true
##[debug]Agent.BuildDirectory=D:\AzureDevOpsData\Agents\MyAgent\_work\18
##[debug]build.buildId=15914
##[debug]Setting auth in the temp nuget.config
"NuGet.config" wird in einer temporären Konfigurationsdatei gespeichert.
##[debug]Getting sources from NuGet.config in this location: D:\AzureDevOpsData\Agents\MyAgent\_work\18\Nuget\tempNuGet_12914.config

临时 NuGet.Config:

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
    
  <add key="feed-MyFeed" value="https://MyAdsUrl.de/MyCollection/_packaging/MyFeed/nuget/v3/index.json"/></packageSources>
  <config>
    <add key="http_proxy" value="http://www-cache.MyProxy.de:3000"/>
    <add key="https_proxy" value="http://www-cache.MyProxy.de:3000"/>
  </config>
  <packageSourceCredentials>
    
  <feed-MyFeed><add key="Username" value="VssSessionToken"/><add key="ClearTextPassword" value="QhbGcsadsasadd... VERY LONG KEY-PA"/></feed-MyFeed></packageSourceCredentials>
</configuration>

从我的角度来看,我可以看到临时 Nuget.Config 包含我的自定义代理和我的自定义提要,但 我的自定义身份验证。

这是否意味着 dotnet 任务不使用我的自定义 NuGet.Config


元信息

  • ADS 和代理是自托管的
  • 版本:17.153.29207.5(AzureDevOps2019.Update1)
  • 代理:是

最佳答案

您可以尝试将 Azure 工件源的凭据放入 nuget.config 文件中。

首先你需要生成一个Personal access token来自具有读取和写入打包范围的 Azure DevOps。

然后,您可以向您的 nuget 源的 azure feed 提供凭据。请参阅下面的示例:

<configuration>
  <packageSources>
    <add key="AzureArtifactFeedName" value="http://dctfs2019:8080/tfs/Collection/_packaging/AzureArtifactFeedName/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <AzureArtifactFeedName>
        <add key="Username" value="any" />
        <add key="ClearTextPassword" value="{Personal Access Token}" />
      </AzureArtifactFeedName>
  </packageSourceCredentials>
</configuration>

您还可以运行以下命令来添加 Feed 凭据:

sources Add -Name "AzureArtifactFeedName" -Source "http://dctfs2019:8080/tfs/Collection/_packaging/AzureArtifactFeedName/nuget/v3/index.json" -username any -password PersonalAccessToken -ConfigFile path/to/Nuget.config -StorePasswordInClearText

然后就可以自动推送包了。

此外,您可以尝试添加 <add key="ValidAuthenticationTypes" value="basic"/>到包源凭据,以防止 nuget/dotnet 尝试通过 NTLM/Windows 身份验证进行身份验证。

关于azure-devops - Azure DevOps Server dotnet Restore 无法访问源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65004043/

相关文章:

continuous-integration - 如何从 PowerShell 设置 Azure 管道变量

azure-devops - 如何在不进行部署的情况下调试和开发Azure DevOps扩展?

azure - 如何使用 Azure DevOps 管道变量配置 Azure Function?

nuget - AzureDevOps 不会从 AzureDevOps 源恢复包

azure - Kubectl 的任何备用命令描述 pods <podname>

powershell - 我可以在 PowerShell 中迭代 JSON 数组吗?

Azure DevOps Powershell 脚本无法创建 SSL/TLS 安全通道

powershell - 如何使用发布管理 (团队服务) 在任务之间的 Azure VM 上运行 Powershell 脚本

git - Visual Studio Online - 无法解析版本描述符 <BranchName>

azure - npm Azure Artifacts feed 不会安装来自上游源的所有依赖项