在企业代理后面的Linux上使用.NET Core 2.1 + VS Code创建一些单元测试时,我遇到了一些麻烦。尽管我对.NET和Visual Studio有经验,但是我对VS Code和.NET Core还是比较陌生。
我可以成功创建解决方案( dotnet new sln ),类库( dotnet new classlib )/控制台应用程序( dotnet new console )项目,并将它们正确链接在一起。但是,当尝试使用以下命令执行 Unit Testing 时:
dotnet new xunit,
dotnet恢复操作失败。上述命令的输出如下:
/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#的VS Code扩展(C#,Nuget Package Manager,Omnisharp等)。公司代理人。
我认为该错误可能与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
预先感谢;)。
答案 0 :(得分:1)
经过多次尝试,这才对我有用。
我必须使用以下命令安装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 Code集成终端(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'.
希望它会有所帮助;)