如何通过令牌非交互式认证安装Azure Artifacts源的Dotnet Tool?
解决方法
以下几种方案可实现非交互式的Azure Artifacts源认证,完成dotnet工具安装:
1. 预先配置NuGet配置文件
创建或修改nuget.config文件,将带PAT认证的源写入其中,安装时指定该配置文件即可:
- 编写
nuget.config内容:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="MyAzureFeed" value="<my-source-url>" /> </packageSources> <packageSourceCredentials> <MyAzureFeed> <add key="Username" value="任意用户名(比如PAT)" /> <add key="ClearTextPassword" value="<你的PAT令牌>" /> </MyAzureFeed> </packageSourceCredentials> </configuration>
- 安装工具时指定配置文件:
dotnet tool install MyTool --tool-path . --configfile nuget.config
2. 预先添加带认证的NuGet源
通过dotnet nuget add source命令预先配置带PAT认证的源,后续安装无需重复指定认证信息:
dotnet nuget add source <my-source-url> --name MyAzureFeed --username 任意用户名 --password <你的PAT令牌> --store-password-in-clear-text
执行完上述命令后,直接运行安装命令:
dotnet tool install MyTool --tool-path . --source MyAzureFeed
注:
--store-password-in-clear-text参数会将密码明文存储在本地配置中,适合自动化环境使用。
3. 直接在源URL中嵌入PAT
将PAT直接嵌入到源URL中,格式为https://<任意用户名>:<PAT>@<feed-url>,安装命令如下:
dotnet tool install MyTool --tool-path . --add-source https://user:<你的PAT令牌>@<my-source-url>
Azure Artifacts对用户名无严格要求,填任意字符串均可,只要PAT有效即可。
内容的提问来源于stack exchange,提问作者MLavrentyev
相关产品推荐
相关产品推荐

