Setup Visual Studio Proxy Setting


If you are working with Visual Studio behind your company proxy you may face many issues like failed to load nuget packages ,failed to load Visual Studio Extensions and Updates or failed to login with your Microsoft account within Visual Studio.

To solve these problems we have to let visual studio use our proxy correctly , to setup the proxy settings :

Open visual studio folder ,according to your version it may be something like .( C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE )

Open ( devenv.exe.config ) file and inside <system.net> node add the bellow :

<system.net> 
  <defaultProxy useDefaultCredentials="true" enabled="true"> 
    <proxy bypassonlocal="true" proxyaddress="http://[proxyURL]:[Port]" />
  </defaultProxy>
</system.net>

if  you got an error like :

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.......

it mean that you need to force the .NET framework to use TLS 1.2 when connecting using  HTTPS , to solve this error just create a new .reg file and put the following text in it and run it .

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

but based on you proxy you may face the : 407 error (Proxy authentication required) when Team Explorer trying to connect to your TFS server , to solve this issue you have to create a DLL with a custom proxy module that provides the credentials and the code will be something like :

using System;
using System.Net;
 
namespace Fayed.AuthProxy
{
    public class AuthProxyModule : IWebProxy
    {
        ICredentials crendential = new NetworkCredential("proxy.user", "password");
 
        public ICredentials Credentials
        {
            get
            {
                return crendential;
            }
            set
            {
                crendential = value;
            }
        }
 
        public Uri GetProxy(Uri destination)
        {
            return new Uri("http://proxy:8080", UriKind.Absolute);
        }
 
        public bool IsBypassed(Uri host)
        {
            return host.IsLoopback;
        }
    }
}

and the configuration will be like :

<system .net="">
 <defaultproxy>
  <module type="Fayed.AuthProxy.AuthProxyModule, Fayed.AuthProxy">
 </module></defaultproxy>
</system>


That's it :)

sources :

https://msdn.microsoft.com/en-us/library/dn771556(v=vs.120).aspx

https://blogs.msdn.microsoft.com/rido/2010/05/06/how-to-connect-to-tfs-through-authenticated-web-proxy/

https://stackoverflow.com/a/38053045/1312036

5 comments:

  1. The open and worldwide nature of internet business is probably going to expand advertise size and change showcase structure, both as far as the number and size of players and the manner by which players contend on universal markets. prywatnoscwsieci

    ReplyDelete
  2. This is the type of information I’ve long been trying to find. Thank you for writing this information. 1337x

    ReplyDelete
  3. The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. 1337x

    ReplyDelete
  4. If you are using the Internet on a regular basis, you are probably interested in the topic of how to increase your Internet speed. Some surveys suggest that people are generally never satisfied with their speed of their Internet connection, regardless of what their Internet speed actually is at any given moment. Unblock Kickass

    ReplyDelete
  5. Nice Post!!
    Thanks for Sharing and Commenting
    Are You Looking for Buy Real Tiktok followers, Likes and TikTok Video Post Likes,Comments,Profile Follow and Etc..
    Buy Real TikTok Likes
    Buy Musically Fans
    7 Best Ways to Make Money on YouTube in 2020


    ReplyDelete