我有一个 Azure 函数,它依赖于私有包源。
我正在将
nuget.config
文件复制到应用程序服务,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyPackageFeed" value="<package feed path>" />
</packageSources>
<packageSourceCredentials>
<MyPackageFeed>
<add key="Username" value="<first part of Hotmail address, before @ symbol>" />
<add key="Password" value="<newly generated access token for username>" />
</MyPackageFeed>
</packageSourceCredentials>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
注意: 我使用 Hotmail 帐户电子邮件地址的第一部分,因为这是我用来对其他地方的私人源进行身份验证的用户名 - Visual Studio 等。
这是我在Azure功能门户的日志中看到的:
2016-10-05T11:57:16.974 Restoring packages.
2016-10-05T11:57:16.974 Starting NuGet restore
2016-10-05T11:57:18.381 Restoring packages for D:\home\site\wwwroot\HttpTriggerSqlDb\project.json...
2016-10-05T11:57:19.322 Unable to load the service index for source <path to feed>
2016-10-05T11:57:19.322 The parameter is incorrect.
如果我按照 @brettsam 的建议将
Password
键更改为 ClearTextPassword
,我现在会得到以下结果:
2016-10-05T14:03:04.479 Please provide credentials for: <path to feed>
2016-10-05T14:03:05.097 Unable to load the service index for source <path to feed>
2016-10-05T14:03:05.097 Response status code does not indicate success: 401 (Unauthorized).
2016-10-05T14:03:05.142 UserName: Password:
尝试使用
key="ClearTextPassword"
(而不是 key="Password"
)。如果您使用 Password
,NuGet 会假定该值已加密并将尝试解密它。
例如,我在 VSTS 中创建了一个包 feed,然后创建了一个个人访问令牌并使用了这个:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyPrivateFeed" value="https://brettsam.pkgs.visualstudio.com/_packaging/stackoverflow/nuget/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSourceCredentials>
<MyPrivateFeed>
<add key="Username" value="brettsam" />
<add key="ClearTextPassword" value="{PAT}" />
</MyPrivateFeed>
</packageSourceCredentials>
</configuration>
IMO 实现这一目标的更好方法。
上面的答案没有错,有效。唯一的问题是 PAT 密钥暴露了。
您可以使用 NuGet 命令行来为您完成这项工作。
如果您没有 nuget cli,请安装。
nuget sources add -name <Feed_Name> -source <Feed_URL> -username <Any_String_But_Not_Null> -password <Personal_Access_Token>
当您现在检查 NuGet.Config 文件时,您会发现它添加了加密密码,而不是明文密码。
享受编码的乐趣;)
用户名通常是 Azure DevOps 中的组织名称,密码是您的 PAT。
参考: