简体   繁体   English

如何使用凭据正确配置外部nuget包源?

[英]How to properly configure external nuget package source with credentials?

I have an external nuget package source in my project wich I added in Visual Studio 2017 by the Package Manager Settings . 我在我的项目中有一个外部nuget软件包源,这是我在Visual Studio 2017中通过``软件包Package Manager Settings I can install the packages properly but when I click on publish (it´sa dotnet core console app). 我可以正确安装软件包,但是单击“ publish (这是一个dotnet核心控制台应用程序)时。 I get this error status: 我收到此错误状态:

2>Retrying 'FindPackagesByIdAsync' for source 'https://***.azure.com/*****/system.servicemodel.duplex/index.json'. 2>重试源'https://***.azure.com/*****/system.servicemodel.duplex/index.json'的'FindPackagesByIdAsync'。 2>Response status code does not indicate success: 401 (Unauthorized). 2>响应状态代码不指示成功:401(未授权)。

I searched a solution which says to add the credentials using the cmd , but when I try to execute the command to add I get this error message from the cmd: 我搜索了一个说使用cmd添加凭据的解决方案,但是当我尝试执行添加命令时,我从cmd收到了以下错误消息:

The name specified has already been added to the list of available package sources. 指定的名称已被添加到可用软件包来源列表中。 Please provide a unique name. 请提供一个唯一的名称。

So I need to remove the package source from the visual studio (using the Package Manager Settings) and after I remove the package source the cmd command works, but then I dont have access anymore to the external packages in Visual Studio (because I removed it to be possible to add from the command line). 因此,我需要从Visual Studio中删除程序包源(使用“程序包管理器设置”),并且在删除程序包源之后, cmd命令可以工作,但是随后我将无法再访问Visual Studio中的外部程序包(因为我将其删除了)可以从命令行添加)。

How can I fix that? 我该如何解决?

EDIT: The cmd syntax is this: 编辑:cmd语法是这样的:

nuget.exe sources add -name MyExternalSource -source https://***/nuget/v3/index.json -username nugetUser -password MyToken

It needs Identity when pushing or consuming packages through a Azure Devops feed. 通过Azure Devops feed推送或使用程序包时,它需要身份。

I think you don't need to use command like nuget.exe sources Add -Name "TestNuget" -Source "https://xxx/nuget/v3/index.json" , since it is used to manage the package sources in Nuget.config file instead of solving the Unauthorized issue. 我认为您不需要使用nuget.exe sources Add -Name "TestNuget" -Source "https://xxx/nuget/v3/index.json"类的命令nuget.exe sources Add -Name "TestNuget" -Source "https://xxx/nuget/v3/index.json" ,因为它用于管理Nuget.config的软件包源Nuget.config文件,而不是解决未经授权的问题。 See sources command . 请参阅sources命令

I get this error status: 我收到此错误状态:

2>Retrying 'FindPackagesByIdAsync' for source 'https://***.azure.com/*****/system.servicemodel.duplex/index.json'. 2>重试源'https://***.azure.com/*****/system.servicemodel.duplex/index.json'的'FindPackagesByIdAsync'。 2>Response status code does not indicate success: 401 (Unauthorized). 2>响应状态代码不指示成功:401(未授权)。

Most of the time, I met this kind of message when using Self-Contained deploy mode. 大多数时候,在使用自包含部署模式时,我都会遇到此类消息。 But actually the publish can succeed in my machine with message like this: 但是实际上发布可以在我的机器中成功,并显示以下消息:

在此处输入图片说明

(I think the publish also succeeds in your side, in this situation I think you can ignore it or publish the project the second time with same PublishProfile, the error message would go away) (我认为发布也可以在您的身边成功,在这种情况下,我认为您可以忽略它或使用相同的PublishProfile第二次发布项目,错误消息就会消失)

Also you can publish the project with Framework-dependent mode after builds the project successfully. 成功构建项目后,您还可以使用依赖框架的模式发布项目。

If the publish failed: 如果发布失败:

1.And if your publish fails with that message, in my opinion you can remove the referenced packages by Nuget Package Manager UI , and remove the Feed Url from Package Sources UI . 1.如果发布失败并显示该消息,我认为您可以通过Nuget Package Manager UI删除referenced packages ,并从Package Sources UI删除Feed Url

2.Then restart VS and re-set the Feed Url in Package Sources Setting . 2.然后重新启动VS,并在“ Package Sources Setting re-set Feed网址。 No need to use command-line, use VS2017 UI and re-add the package after re-set the Package Source. 重新设置包源后,无需使用命令行,使用VS2017 UI并重新添加包。

3.When you search the package from new-set feed like this , it will pop up an Identity Window which requires you to enter account and password, and then you're now authorized . 3.当您像这样从新设置的提要中搜索软件包时,它将弹出一个身份窗口 ,要求您输入帐户和密码,然后您便获得了授权 After that you can find, consume the package in your project, and publish it successfully. 之后,您可以找到并使用项目中的包,然后将其成功发布。 Hope it helps. 希望能帮助到你。

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

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