How to set proxy in visual studio 2015

扶醉桌前 提交于 2019-11-30 22:33:29
Svekke

Find devenv.exe.config in your installation directory.

Now open this text file and add the node <defaultProxy> inside the node <system.net>.

<system.net>
<defaultProxy useDefaultCredentials="true" enabled="true">
    <proxy bypassonlocal="true" proxyaddress="http://yourproxyaddress.net:8080" />
</defaultProxy>
</system.net>

If your proxy requires authentication, you should add those as parameters in the proxy URL

<system.net>
<defaultProxy useDefaultCredentials="true" enabled="true">
    <proxy bypassonlocal="true" proxyaddress="http://Username:Password@yourproxyaddress.net:8080" />
</defaultProxy>
</system.net>

You could create your own proxy authentication module like descriped here:

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

First create a new Visual C# Project -> Class Library (.Net Framework): Name: ProxyModule (for example). USER, PWD and PROXY must be set to the correct string values:

using System.Net;
using System.Net.Sockets;

namespace ProxyModule
{
  public class AuthProxyModule : IWebProxy
  {
    ICredentials crendential = new NetworkCredential("USER", "PWD");

    public ICredentials Credentials
    {
        get
        {
            return crendential;
        }
        set
        {
            crendential = value;
        }
    }

    public Uri GetProxy(Uri destination)
    {
        return new Uri("http://PROXY:8000", UriKind.Absolute);
    }

    public bool IsBypassed(Uri host)
    {
        return host.IsLoopback;
    }
  }
}

and copy the created "ProxyModule.dll" to the "...\Common7\IDE" folder, VS 2015:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

or VS professional 2017:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE

Then you must extend the system.net part in the devenv.exe.config in the same folder:

<system.net>
  <defaultProxy>
    <module type="ProxyModule.AuthProxyModule, ProxyModule"/>
  </defaultProxy>
</system.net>

If you don´t want to use the proxy in some cases you can extend the method "IsBypassed(Uri host)". Maybe you could check your own IP to enable or disable the proxy (return false to disable the proxy).

For the folks that are behind a proxy and using Visual Studio 2017 with Windows 10, this is what I did.

Type "Setting" in the search bar and select Setting to follow to Network & Internet->Proxy then on the bottom you will see Manual proxy setup what I did wat turn on the "Use a proxy server" and put your company address and port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!