访问vsts私有nuget

时间:2023-03-09 13:24:37
访问vsts私有nuget

访问vsts私有nuget

Intro

有时候我们可能要自己搭建一个 nuget,如果不对外公开,即包浏览也是需要权限的,那我们应该怎么做才可以支持在哪里都可以正常的还原包呢?

我是在 VSTS(Visual Studio Team Service) 上新建了一个私有的 nuget,下面介绍怎么做才能不影响包的还原(其他的如myget等类似)。

生成 PAT

PAT(Personal Access Token)

在用户的 Security 下可以生成一个 Personal Access Token,可以选择访问权限的scope,建议只选择 Packaging (read) 的 scope 以保持最小化的权限设置以及安全性。

配置 nuget.config

在项目根目录下增加 nuget.config

文件内容示例如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="weihanli" value="https://weihanli.pkgs.visualstudio.com/_packaging/weihanli/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<weihanli>
<add key="Username" value="weihanli@outlook.com" />
<add key="ClearTextPassword" value="place your pat here" />
</weihanli>
</packageSourceCredentials>
</configuration>

在 packagesources 节点下定义nuget feed源地址,在 packageSourcesCredentials 节点下定义 source 的访问权限,Username 设置为上一步请求 PAT 的账号,ClearTextPassword 设置为生成的 PAT.

Reference

Contact

Contact me:weihanli@outlook.com