0
votes

I'm having some troubles while creating some Unit Tests with .NET Core 2.1 + VS Code on Linux behind a corporate proxy. I'm fairly new to VS Code and .NET Core, although I have experience with .NET and Visual Studio.

I can successfully create a solution (dotnet new sln), Class Library (dotnet new classlib)/Console Application (dotnet new console) projects and properly link them together. However, when attempting to perform Unit Testing with:

dotnet new xunit,

the dotnet restore operation fails. The output of the aforementioned command is the following:

/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]

The error messages suggest that this could be related to some proxy configuration issues (HTTP 407 error issued), but I'm perfectly able to install VS Code extensions for C# (C#, Nuget Package Manager, Omnisharp, etc.) behind the corporate proxy.

I think the error might be related to the NuGet proxy configuration. I followed these instructions (on Linux the file I used was ~/.nuget/NuGet/NuGet.Config), but none of the recommendations worked for me.

In case it helps:

$ 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

Thanks in advance ;).

1
If it helps, I've found a temporal workaround, but it's not quite what I'm looking for. We install JonDo and set <add key="http_proxy" value="http://localhost:4001" /> in ~/.nuget/NuGet/NuGet.Config.ryuzakyl

1 Answers

3
votes

After many attempts, this is what ended working for me.

I had to install nuget command line utility with:

sudo aptitude install nuget

for more details see this post. The next step is to configure nuget to use proxy:

# 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

The config file where such changes will be stored is ~/.config/NuGet/NuGet.Config. Inside VS Code integrated terminal (Ctrl + `), try to download a package:

$ dotnet add package Newtonsoft.Json

and you should be able to see an output similar to this:

  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'.

Hope it helps ;)