简体   繁体   English

连接到Azure Devops私有NuGet在vs代码中

[英]Connecting to an Azure Devops private NuGet in vs code

We have a private NuGet feed. 我们有一个私人NuGet饲料。 It has been working well with Visual Studio . 它一直与Visual Studio Our developers connect through their Azure account with the private feed. 我们的开发人员通过他们的Azure帐户与私有Feed连接。 I'd like to keep this same functionality when moving to vs code. 移动到vs代码时,我想保留相同的功能。

Using the documentation found here I added a nuget.config to my solution folder. 使用此处的文档我将nuget.config添加到我的解决方案文件夹中。 The config looks exactly like the documentation except it has our private feed there. 配置看起来与文档完全一样,除了它有我们的私人提要。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!-- remove any machine-wide sources with <clear/> -->
    <clear />
    <!-- add an Azure Artifacts feed -->
    <add key="PrivateFeed" value="https://pkgs.dev.azure.com/redacted/_packaging/redacted/nuget/v3/index.json" />
    <!-- also get packages from the NuGet Gallery -->
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>

With Visual Studio you simply have to log in and you can connect to the feed. 使用Visual Studio您只需登录即可连接到源。 Where is this option for vs code? vs代码的这个选项在哪里? I'm currently receiving the error messages below which is a good thing because obviously I'm not authenticated. 我目前收到下面的错误消息,这是一件好事,因为显然我没有经过身份验证。 I was expecting some kind of dialog to pop up or having to enter my credentials somewhere. 我期待某种对话框弹出或不得不在某处输入我的凭据。 The dotnet restore command also does not have any way of providing credentials as far as I'm aware. 据我所知,dotnet restore命令也没有任何提供凭据的方法。

C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/redacted/_packaging/redacted/nuget/v3/index.json. [redacted]
C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error :   Response status code does not indicate success: 401 (Unauthorized). [redacted]

Some documentation also mentions putting credentials in the nuget.config file but I find this very strange as this was never necessary with Visual Studio and I also don't have a user I can just enter here. 有些文档还提到在nuget.config文件中放置凭据,但我觉得这很奇怪,因为这对Visual Studio是不必要的,而且我也没有用户可以在这里输入。 Surely creating a service account just for a private NuGet is a step too far? 当然,为私人NuGet创建一个服务帐户是一个太过分了吗?

<packageSourceCredentials>
    <Contoso>
        <add key="Username" value="user@contoso.com" />
        <add key="ClearTextPassword" value="33f!!lloppa" />
    </Contoso>
</packageSourceCredentials>

How can I connect to a private NuGet feed on Azure Devops with vs code without saving credentials in a file? 如何使用vs代码连接到Azure Devops上的私有NuGet订阅源而不保存文件中的凭据?

How can I connect to a private NuGet feed on Azure Devops with vs code without saving credentials in a file? 如何使用vs代码连接到Azure Devops上的私有NuGet订阅源而不保存文件中的凭据?

I am afraid you have to save the credentials in nuget.config file at this moment. 我恐怕你现在必须在nuget.config文件中保存凭据。

When you log in Visual Studio and connect to the feed with credentials, Visual Studio will verify the credential and save it in the Visual Studio with login credentials: 当您登录Visual Studio并使用凭据连接到订阅源时,Visual Studio将验证凭据并使用登录凭据将其保存在Visual Studio中:

在此输入图像描述

But there is no such sign option for Visual Studio code. 但Visual Studio代码没有这样的签名选项。 So, we have to put credentials in the nuget.config file. 因此,我们必须将凭据放在nuget.config文件中。

Besides, there is a user voice about it, you can vote and add your comments for this feedback. 此外,还有一个用户声音,您可以投票并添加您对此反馈的评论。 When there are enough communities vote and add comments for this feedback, the product team member will take this feedback seriously.: 当有足够的社区投票并为此反馈添加评论时,产品团队成员将认真对待此反馈:

Be able to use VSTS Package Manager with Visual Studio Code (VS Code) 能够使用VSTS包管理器与Visual Studio代码(VS代码)

Hope this helps. 希望这可以帮助。

We ended up using https://github.com/Microsoft/artifacts-credprovider for VS Code. 我们最终使用https://github.com/Microsoft/artifacts-credprovider for VS Code。 It works really well. 它工作得很好。 Just follow the steps to install the Microsoft.NuGet.CredentialProvider. 只需按照步骤安装Microsoft.NuGet.CredentialProvider即可。 Afterwards you should be able to restore the packages with the command "dotnet restore --interactive". 之后,您应该能够使用命令“dotnet restore --interactive”恢复软件包。

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

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