繁体   English   中英

如何从 Windows 上的 devcontainer 中的私有 NugetFeed 恢复 Nuget 包?

[英]How do I restore Nuget Packages from a private NugetFeed in a devcontainer on Windows?

我使用的是 Windows,安装了 Docker(使用 lunix 容器),安装了 VS Code 和 devcontainer 扩展。 我从私有 NugetFeed 加载了一个使用 Nugets 的项目,当我尝试恢复(交互式)NugetPackages 时,我从 NugetFeed 收到 401 错误。

/usr/share/dotnet/sdk/2.2.207/NuGet.targets(119,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/[SomeFeedUrl]/nuget/v3/index.json. [/workspaces/[SomeSolution].sln]
/usr/share/dotnet/sdk/2.2.207/NuGet.targets(119,5): error :   Response status code does not indicate success: 401 (Unauthorized). [/workspaces/[SomeSolution].sln]

我在本地尝试了同样的事情(安装了凭据提供程序),一切正常。 我还尝试将 Nugetpackages 路径安装到 devcontainer,在本地恢复,然后启动项目(因为这是我的修复,可以让恢复在我的 linux 机器上正常工作)。

这是我的 devcontainer.json 的样子:

// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/azure-functions-dotnetcore-2.2
{
    "name": "Azure Functions & C# (.NET Core 2.2)",
    "dockerFile": "Dockerfile",

    // Use 'settings' to set *default* container specific settings.json values on container create. 
    // You can edit these settings after create using File > Preferences > Settings > Remote.
    "settings": { 
        "terminal.integrated.shell.linux": "/bin/bash"
    },

    "mounts": [
        "source=C:/Users/[user]/.nuget,target=/home/vscode/.nuget,type=bind"
        // "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind"
    ],

    "remoteEnv": {
        // [Optional] Override the default HTTP endpoints - need to listen to '*' for appPort to work
        "ASPNETCORE_Kestrel__Endpoints__Http__Url": "http://*:5000"
        // "ASPNETCORE_Kestrel__Endpoints__Https__Url": "https://*:5001",
        // "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere",
        // "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx",
    },

    // Uncomment the next line to run commands after the container is created.
    // "postCreateCommand": "dotnet restore",

    // Uncomment the next line to have VS Code connect as an existing non-root user in the container. 
    // On Linux, by default, the container user's UID/GID will be updated to match your local user. See
    // https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist.
    // "remoteUser": "vscode",

    // Add the IDs of extensions you want installed when the container is created in the array below.
    "extensions": [
        "ms-azuretools.vscode-azurefunctions",
        "ms-vscode.csharp"
    ]
}

我没有接触 dockerfile,dockerfile 仍然是一个股票 dockerfile。

有没有人有同样的问题/知道如何让它正常工作?

目前,没有干净的方法可以做到这一点。 我认为 #1 解决方案应该更容易设置。

解决方案#1

  1. 打开.devcontainer/devcontainer.json并将条目添加到mounts部分(您可以将src值更改为其他值 - 这是您的令牌将被存储的卷的名称):

    "src=credprovider-data,dst=${env:HOME}/.local/share/MicrosoftCredentialProvider,type=volume"

  2. 打开.devcontainer/Dockerfile添加在最后:
# Download and install Azure DevOps Credential provider
&& curl -sL https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash -
  1. 保存两个文件并重建容器
  2. 在容器中打开bash并执行: dotnet restore --interactive
  3. 单击链接,应该会打开您的浏览器。 键入代码并按 ENTER。 现在,取决于您是否已登录,系统会要求您登录。登录到 Azure DevOps 后,您将看到消息,提示您现在可以关闭窗口。 几秒钟后,您将在 DevContainer 中看到dotnet restore继续并下载您的提要。

这个方法在重启后应该是持久的,甚至容器也会重建。

解决方案#2

您还可以将 PAT(个人访问令牌)作为VSS_NUGET_ACCESSTOKEN环境、Feed URL,在容器中设置VSS_NUGET_EXTERNAL_FEED_ENDPOINTSNUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED环境变量。

另请在此处查看: https : //github.com/Microsoft/artifacts-credprovider#help

与您的问题相关的 Github 问题:

我正在使用 VS 代码。 在 VS 2015\/2019 上它对我来说很好,只有在 VS Code 上我有这个问题。 我跟踪了所有链接并尝试了很多东西,但最后我解决了在提升的 CMD 上探索dotnet nuget<\/code>命令的问题。

为我解决它的配置是:

返回:

暂无
暂无

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

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