Configuring Proxy Settings in Visual Studio Code

Comments: 0

The unrivaled popularity of Visual Studio Code as a code editor stems from its functionality on all major operating systems, support for multiple programming languages, a plethora of built-in tools, and the ability to edit code seamlessly without necessitating the installation of a development environment. Despite these features, developing cloud-based or web applications remains impossible without network access, which may be restricted for a variety of reasons. Proxy settings in VScode address many of these issues while maintaining external resource security.

Why Configure Proxy in VScode?

Practical use cases for enabling a proxy for VScode include concealing one’s IP address and enhancing privacy. However, the applications of such servers extend far beyond that scope. These include but are not limited to:

  • downloading libraries and language-specific extensions;
  • accessing APIs;
  • working with remote repositories;
  • testing web resources;
  • controlling extension downloads from the Visual Studio Marketplace and limiting network requests made by executable code;
  • automatic updates of the editor itself.

The ease of handling all of these tasks, especially in geo-fenced or high-security controlled environments with traffic filtering policies, becomes possible in case you configure a proxy in VScode.

How to Set Proxy in VScode

Similar to other development tools, Microsoft’s editor has the option for configuring an intermediary server for internet access. This can be achieved in several different ways depending on the user’s operating system.

Configuring Proxy Settings in VS Code UI

The UI method is usually the simplest one. As much as it is beneficial for customers, Microsoft has guide notes. Although informative, it is missing the add or edit steps in the setting.json file, which is crucial for the proxy settings in VScode to function properly. Check the additional steps for improvement:

  1. Open VS Code, click the gear icon, and select “Settings”.

    1.png

  2. In the “Application” section, click on “Proxy”, and enter your IP address in one of the following forms:
    • http://username:password@host:port — for authenticating;
    • http://host:port — with no authentication.

    2.png

    Note: If your password has @, #, *, and other characters, then those have to be substituted with ASCII codes prefixed by %.

  3. Find the settings.json path according to your OS:
    • Linux: $HOME/.config/Code/User/settings.json;
    • Windows: %APPDATA%/Code/User/settings.json;
    • macOS: $HOME/Library/Application Support/Code/User/settings.json.

    Alternatively, you can click “Edit In settings.json” from the app.

    3.png

  4. Following the instructions, right-click on the file and select “Open”, “Using Notepad”. If you accessed settings.json from the program’s GUI, the editor will open a new tab. In either case, add the code and save.
    
    {
    "http.proxySupport": "on",
    "http.proxy": "http://user:password@host:port",
    "http.proxtStrictSSL": "false",
    "http.proxyAuthorization": null
    }
    
    
  5. To implement the changes restart Visual Studio Code.

Important: The application will default to using system variables if a proxy host isn’t defined in the “http.proxy” field.

How to Set proxy in Visual Studio Code Terminal

Proxy settings can in VScode also be done within the terminal, follow steps below:

  1. Open Terminal by clicking the ellipsis (three dots) then select Terminal → New Terminal.

    5.png

  2. In the command line, enter: code --proxy-server="http://user:password@host:port" for authenticated proxies code --proxy-server="http://host:port" for unauthenticated. Result will look like this:

    13en.png

You may also use https instead of http as necessary.

Setup Proxy in VScode via Environment Variables

This alternative approach is ideal when the previous ones aren’t possible.

  1. Type “Environment variables” in the Windows search bar and select “Edit the system environment variables”.

    6en.png

  2. In the subsequent window, select the “Advanced” tab and click on “Environment Variables”.

    7en.png

  3. Under User variables, click on “New”.

    8en.png

  4. Assign the variable name HTTP_PROXY or HTTPS_PROXY and the value “host:port”.

    9en.png

Important: If you are employing environment variables, do not include the proxy field in settings.json in VS Code, as this may cause connection problems.

Proxy settings in VScode defined in the previous steps are set for all applications globally, which can be problematic, especially if using a private server that requires authentication. If this is your situation, use third-party tools like Docker and write your management code for managing sessions in your language of choice to define the project-specific environment variables.

Troubleshooting Proxy Issues in VS Code

Despite the aforementioned configurations appearing simple, complications may still arise. These are typically the result of the application’s OS settings, editor settings, or user permissions that are too limited.

Proxy Server Cannot Be Reached

This problem can occur when the proxy settings in VScode are defined in the editor's options, set as environment variables, and also included in the Windows credentials simultaneously. In such circumstances, you need to focus on one configuration method as explained above. However, in addition to the options already discussed, there’s another possible issue — stored intermediary credentials in Windows. Here's how to remove them:

  1. Open Control Panel → Credential Manager → Windows Credentials.

    10en.png

  2. Locate the credential containing the proxy server information. Remove this credential.

    11en.png

  3. After this, set proxy for Visual Studio using any method detailed above and ensure to perform a PC restart.

Proxy Server Authentication Required

When you set up a VScode proxy for extensions it often triggers such errors with various codes. This issue is usually resolved by simply restarting the editor and re-entering your login and password in the settings.

That said, the issue might also arise from the intermediary server credential prompts for *visualstudio.microsoft.com domains instead of the *.microsoft.com domains.

Within Windows settings, append the proposed URLs to the list of domains:

  • *.windows.net
  • *.microsoftonline.com
  • *.visualstudio.microsoft.com
  • *.microsoft.com
  • *.live.com

Now, open Command prompt with Administrator privileges and execute the command below to establish the appropriate host and port:


netsh winhttp set proxy proxy:port

12en.png

Best Proxies for Visual Studio Code?

If you made up your mind to configure a proxy settings in VScode and are wondering which one to go with, let’s explore that a bit.

In particular, Microsoft states that the code editor accommodates every conceivable type utilizing HTTP and HTTPS protocols.

We propose tackling the selection process in two phases:

  • comprehend the distinction between the protocols;
  • define the server in relation to main objectives.

The difference between data transmission protocols, HTTP and HTTPS, is that one is encrypted. HTTP, the first option, does not offer any encryption, whereas the second one, HTTPS, seeks to ensure utmost protection of the information being transmitted.

In addition to encryption, there are other factors that differentiate these two protocols; the level of security and performance. Data in the HTTP protocol is transmitted by means of a “request–response” model. It does not guarantee anonymity. HTTPS guarantees much stronger security. Data is wrapped, encrypted, and sent to the server with no access to its content. Here three levels of protection are in operation: confidentiality, encryption and authentication. As stated previously, the request handling speed is slower than unencrypted HTTP due to the second protocol's time requirement to encrypt data. Proxy settings in VScode, when set incorrectly, will have an unpleasant impact on the editor's overall performance.

Having reviewed the specifics of HTTP and HTTPS, let’s define the use cases for each protocol in software development. After this you will know what exactly you need if you want to buy a proxy server for Visual Studio.

If you build web applications that require advanced security features, such as social networking sites, messaging applications, email services, or even VoIP, then proxies with at least an HTTPS level of security should be your focus.

On the other hand, if you offer services which require instant loading times across devices and do not require any user login, then HTTP would be more suitable. Both residential and mobile proxies, as well as datacenter ones, support both protocols. The selected intermediary server should depend on the stated tasks. To more thoroughly evaluate it follow the provided link in the full article.

Proxy Settings in VScode: Conclusion

Having gone through how to set proxy in Visual Studio, the factors that determine the best solution, we can note that such setting is crucial in ensuring proper operation, especially in an environment with restricted internet access. With the help of such a server, developers can beyond borders get illegal access to novel and restricted resources including remote repositories, extension marketplaces, update servers, and others which are vital for their advancement.

Comments:

0 comments