You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TeamCity中如何配置Dotnet CLI使用AWS CodeArtifact登录凭证?

解决Dotnet CLI无法识别AWS CodeArtifact登录凭证的问题

问题本质

aws codeartifact login默认仅配置MSBuild依赖的Windows NuGet凭证管理器,而.NET CLI使用独立的凭证存储机制,因此无法自动识别前者设置的凭证信息,导致恢复NuGet包时出现error NU1301。

解决方案

1. 用AWS CLI直接配置Dotnet CLI凭证

执行aws codeartifact login时添加--tool dotnet参数,命令会同时配置MSBuild和Dotnet CLI的NuGet源及凭证:

aws codeartifact login --tool dotnet --repository <你的仓库名> --domain <你的域名> --domain-owner <AWS账号ID> --region <区域>

该命令会自动更新Dotnet CLI对应的NuGet配置文件,将CodeArtifact源和临时授权凭证写入其中。

2. 手动配置Dotnet CLI的NuGet源与凭证

如果自动配置失效,可手动完成以下步骤:

  • 获取CodeArtifact授权令牌:
    aws codeartifact get-authorization-token --domain <你的域名> --domain-owner <AWS账号ID> --region <区域> --query authorizationToken --output text
    
  • 添加CodeArtifact源到Dotnet CLI:
    dotnet nuget add source https://<域名>-<账号ID>.d.codeartifact.<区域>.amazonaws.com/nuget/<仓库名>/v3/index.json --name <自定义源名称>
    
  • 设置源的凭证(用户名固定为aws,密码为上述获取的令牌):
    dotnet nuget update source <自定义源名称> --username aws --password <获取到的授权令牌>
    

3. 确保TeamCity构建环境的上下文一致性

  • 确保执行aws codeartifact login的构建步骤与dotnet msbuild步骤在同一个构建代理会话中运行,保证环境变量和配置文件能被正确继承。
  • 若仍有问题,可在dotnet msbuild命令中显式指定NuGet配置文件路径:
    dotnet msbuild -t:restore -t:build /p:NuGetConfigPath=<aws login生成的配置文件路径>
    

验证

执行以下命令确认源和凭证配置正确:

dotnet nuget list source

内容的提问来源于stack exchange,提问作者Iceape

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 06:42:35