代码之家  ›  专栏  ›  技术社区  ›  ryuzakyl

企业代理背后的Linux上的dotnet恢复、nuget和vs代码问题

  •  0
  • ryuzakyl  · 技术社区  · 7 年前

    我在用公司代理后面的Linux上的.NET核心2.1+vs代码创建一些单元测试时遇到了一些问题。虽然我在.NET和Visual Studio方面有经验,但我对VS代码和.NET核心还比较陌生。

    我可以成功创建解决方案( 新网 )类库( dotnet新类库 )/控制台应用程序( Dotnet新控制台 )项目并将它们正确地连接在一起。但是,在尝试执行时 单元测试 用:

    dotnet new xunit,
    

    这个 网络还原 操作失败。上述命令的输出如下:

    /usr/share/dotnet/sdk/2.1.301/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/home/ryuzakyl/Desktop/CSharpWithVSCode/test/CSharpWithVSCode.Tests/CSharpWithVSCode.Tests.csproj]
    
    /usr/share/dotnet/sdk/2.1.301/NuGet.targets(114,5): error : Response status code does not indicate success: 407 (Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )). [/home/ryuzakyl/Desktop/CSharpWithVSCode/test/CSharpWithVSCode.Tests/CSharpWithVSCode.Tests.csproj]
    

    错误消息表明这可能与一些代理配置问题(HTTP 407错误问题)有关,但我完全能够在公司代理背后安装针对C(C、Nuget Package Manager、Omnisharp等)的VS代码扩展。

    我认为错误可能与nuget代理配置有关。我跟随 these 说明(在Linux上,我使用的文件是 ~/.nuget/nuget/nuget.config 但是这些建议对我来说都不起作用。

    如果有帮助:

    $ uname --all
    Linux matrix 4.8.0-53-generic #56~16.04.1-Ubuntu SMP Tue May 16 01:18:56 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    
    $ dotnet --version
    2.1.301
    
    $ code --version
    1.30.1
    dea8705087adb1b5e5ae1d9123278e178656186a
    x64
    

    事先谢谢;)。

    1 回复  |  直到 7 年前
        1
  •  1
  •   ryuzakyl    7 年前

    经过多次尝试,这就是我最终的工作。

    我必须安装nuget命令行实用程序:

    sudo aptitude install nuget
    

    有关详细信息,请参阅 this 邮政。下一步是将nuget配置为使用代理:

    # set proxy
    $ nuget config -set http_proxy=http://proxy.com:port
    $ nuget config -set https_proxy=http://proxy.com:port
    
    # set username (in my case, the domain name was not necessary)
    $ nuget config -set http_proxy.user=username
    $ nuget config -set https_proxy.user=username
    
    # set password
    $ nuget config -set http_proxy.password=password
    $ nuget config -set https_proxy.password=password
    

    存储这些更改的配置文件是 ~/.config/NuGet/NuGet.Config . 在VS代码集成终端(ctrl+`)内,尝试下载软件包:

    $ dotnet add package Newtonsoft.Json
    

    您应该能够看到类似这样的输出:

      Writing /tmp/tmp2RmRVL.tmp
    info : Adding PackageReference for package 'Newtonsoft.Json' into project '/home/ryuzakyl/Desktop/CSharpWithVSCode/src/CSharpWithVSCode.ClassLib/CSharpWithVSCode.ClassLib.csproj'.
    log  : Restoring packages for /home/ryuzakyl/Desktop/CSharpWithVSCode/src/CSharpWithVSCode.ClassLib/CSharpWithVSCode.ClassLib.csproj...
    info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
    info :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 286ms
    info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project '/home/ryuzakyl/Desktop/CSharpWithVSCode/src/CSharpWithVSCode.ClassLib/CSharpWithVSCode.ClassLib.csproj'.
    info : PackageReference for package 'Newtonsoft.Json' version '12.0.1' updated in file '/home/ryuzakyl/Desktop/CSharpWithVSCode/src/CSharpWithVSCode.ClassLib/CSharpWithVSCode.ClassLib.csproj'.
    

    希望有帮助;)