温馨提示:本文翻译自stackoverflow.com,查看原文请点击:.net - How do I restore Nuget Packages from a private NugetFeed in a devcontainer on Windows?
.net nuget nuget-package-restore visual-studio-code private-nuget-feed

.net - 如何在Windows的devcontainer中从私有NugetFeed还原Nuget软件包?

发布于 2020-04-04 10:52:24

我正在使用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。

是否有人遇到相同的问题/知道如何使其正常工作?

查看更多

提问者
thegreatdane6
被浏览
122
TheAifam5 2020-01-31 23:17

当前,没有干净的方法可以做到这一点。我认为#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继续并下载您的feed。

重新启动后该方法应保持不变,甚至容器也将重建。

解决方案#2

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

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

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