简体   繁体   English

Nuget 还原失败并进行身份验证

[英]Nuget restore fails with authentication

Migrating to my Linux machine for work I have run into a problem with Nuget.迁移到我的 Linux 机器工作我遇到了 Nuget 的问题。 Our projects are .net core 3.1 and each has its own nuget.config file which has four package sources in it.我们的项目是 .net 核心 3.1,每个项目都有自己的 nuget.config 文件,其中包含四个 package 源。 The first is the obvious one but the rest are specific for the company.第一个是显而易见的,但 rest 是该公司专用的。

Whenever I build I get an error stating that I am not authorised:每当我构建时,我都会收到一条错误消息,指出我没有被授权:

/usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error: Unable to load the service index for source https://aldinternational.pkgs.visualstudio.com/_packaging/PLASMA/nuget/v3/index.json . /usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5):错误:无法加载源https://aldinternational.pkgs.visualstudio.com/_packaging/PLASMA/nuget/的服务索引v3/index.json [/home/lg/Documents/ALD/repo/CampaignIngestion.OmegaConnector/OmegaConnector.Functions/OmegaConnector.Functions.csproj] /usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error: Response status code does not indicate success: 401 (Unauthorized). [/home/lg/Documents/ALD/repo/CampaignIngestion.OmegaConnector/OmegaConnector.Functions/OmegaConnector.Functions.csproj] /usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5):错误:响应状态码不表示成功:401(未授权)。 [/home/lg/Documents/ALD/repo/CampaignIngestion.OmegaConnector/OmegaConnector.Functions/OmegaConnector.Functions.csproj] 0 Warning(s) 1 Error(s) [/home/lg/Documents/ALD/repo/CampaignIngestion.OmegaConnector/OmegaConnector.Functions/OmegaConnector.Functions.csproj] 0 警告 1 错误

but I can get the json output when I put that in a browser.但是当我把它放在浏览器中时,我可以得到 json output 。 I have run:我跑了:

mozroots --import --sync --url https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt mozroots --import --sync --url https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt

as the thread I found it on seemed to having a similar issue but for me no luck.因为我发现它的线程似乎有类似的问题,但对我来说没有运气。

dotnet --info output

.NET Core SDK (reflecting any global.json):
 Version:   3.1.301
 Commit:    7feb845744

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.301/

Host (useful for support):
  Version: 3.1.5
  Commit:  65cd789777

.NET Core SDKs installed:
  2.1.302 [/usr/share/dotnet/sdk]
  2.2.300 [/usr/share/dotnet/sdk]
  3.1.301 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

The build is definitely hitting the correct nuget.config and is not using my local use config.该构建肯定达到了正确的 nuget.config 并且没有使用我的本地使用配置。 How can I fix this issue?我该如何解决这个问题?

I have all packages from key="nuget.org" value="https://api.nuget.org/v3/index.json" downloaded as it is the first in the list I think.我下载了来自 key="nuget.org" value="https://api.nuget.org/v3/index.json" 的所有包,因为它是我认为列表中的第一个。

This all came down to adding the correct packageSourceCredentials to the correct nuget.config file.这一切都归结为将正确的 packageSourceCredentials 添加到正确的 nuget.config 文件中。 I have我有

  1. ~/.config/NuGet/nuget.config ~/.config/NuGet/nuget.config
  2. ~/.nuget/NuGet/nuget.config ~/.nuget/NuGet/nuget.config
  3. solution level nuget.config file解决方案级别 nuget.config 文件

Don't use #3 for this as that puts user set up at solution level and it is committed.不要为此使用#3,因为这会将用户设置在解决方案级别并且已提交。 #1 doesn't seem to have any affect when I do "dotnet build" from the project folder.当我从项目文件夹执行“dotnet build”时,#1 似乎没有任何影响。 #2 is the file that needs the credentials set up (for me anyway). #2 是需要设置凭据的文件(无论如何对我来说)。

Next issue is that we have PAT code access set up on our private repo but non-windows platforms do not support the encryption but just placing a clear text password there is no good either.下一个问题是我们在我们的私人仓库上设置了 PAT 代码访问权限,但非 Windows 平台不支持加密,只是放置一个明文密码也没有好处。 What I needed to do was:我需要做的是:

  1. Go to VSTS log in with my account and generate a PAT code Go 到 VSTS 用我的账号登录并生成 PAT 码
  2. Create PackageSourceCredentials section in #2 nuget configuration file在#2 nuget 配置文件中创建 PackageSourceCredentials 部分
  3. for each repo that needs credentials create a section for its name within PackageSourceCredentials section ie for对于需要凭据的每个 repo,在 PackageSourceCredentials 部分中为其名称创建一个部分,即

<add key="PLASMA" value="" protocolVersion="3" /> <add key="PLASMA" value="" protocolVersion="3" />

(PLASMA is defined in #3 nuget.config files on our set up) (PLASMA 在我们设置的#3 nuget.config 文件中定义)

<PLASMA>
      <add key="Username" value="your username for PAT code" />
      <add key="ClearTextPassword" value="Copied PAT code from vsts" />
</PLASMA>

If you just use password instead of ClearTextPassword it does not seem to work and "Copied PAT code" is the one you copy out of vsts.如果您只使用密码而不是 ClearTextPassword,它似乎不起作用,并且“复制的 PAT 代码”是您从 vsts 复制出来的代码。 It does not appear to matter that the package sources I need credentials for are defined in #3 config files and the credentials for them are defined in #2 config file.我需要凭据的 package 源在#3 配置文件中定义,它们的凭据在#2 配置文件中定义似乎并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM