How to install Visual Studio 2021 Preview Behind Corporate Proxy

So you are tempted to get your hands on the shiny Visual Studio 2021 Preview, right? But the evil corporate proxy is once again blocking you from expanding your curiosity? Well, fear no more. Stay with me while I’ll walk you through this in literally just a minute!

  1. Run Fiddler and make sure that fiddler is pointing to your corporate proxy as its gateway.
    1. Select Tools > Options
    2. In the Gateway tab, make sure “Use System Proxy (recommended)” is selected.
    3. Make sure Fiddler is taking care of NTLM authentication, by selecting Rules > Automatically Authenticate.

2. Download Visual Studio 2021 Preview setup from the official website.

3. Run the downloaded executable. You will be prompted to enter credentials for a local Administrator. Don’t enter your credentials yet.

4. Open the following path in your File Explorer: %USERPROFILE%\AppData\Local\Temp\1

5. Look for a folder that contains another folder called “vs_bootstrapper_d15“. The folder has had a 20 character hexadecimal name in my case (i.e. f9f02c848a65f81ccd57), but I’m pretty sure it is a random name.

6. Look for a file named “vs_setup_bootstrapper.exe.config” and open it in your text editor of choice and add the following snippet to the file and save.

<configuration>
...  
  <system.net>
    <defaultProxy>
      <proxy proxyaddress="http://localhost:8888" bypassonlocal="False" />
    </defaultProxy>
  </system.net>
</configuration>

7. Go back to the credential prompt, enter your credentials and hit OK. You are good to go!

How to install Visual Studio 2021 Preview Behind Corporate Proxy

How to fix proxy authentication issues in your development environment

I have written about proxy authentication before and although this annoying problem has been around, many tools still don’t support it well. Specially when it comes to NTLM flavor of it that has been developed by Microsoft long time ago and even many Microsoft tools did not support it until recently.

Proxy servers in my opinion are not the best tools to control internet access. Security benefit they bring us are not much compared to productivity they take away from developers.

In the past I have used many different techniques to overcome this issue (e.g. CNTLM, custom local proxy and more) but the best way that almost always works reliably and securely is to run Fiddler with its “Capture Traffic” turned off (unless you need it for other reasons) and point from your blocked app to it. This way:

  1. Fiddler won’t be capturing all the traffic and it will only proxy the traffic for the applications that are specifically pointing to it.
  2. It takes care of authentication on behalf of you without worrying to store your credentials somewhere that is not safe or having to update your credentials when they change.
  3. You can always close Fiddler when you want to cut the traffic

In the rest of this blog post I will show how you can configure every development tool that I know (and remember) to point to Fiddler as a proxy.

Keep in mind that it doesn’t have to be Fiddler, any other local proxy that can take care of authentication on behalf of the logged in user can do the same.

Please let me know if I have forgotten a developer tool or if you know how to configure another tool and what others to know it. I will add it to the list as soon as possible.

Nuget Package Manager

At this moment Nuget Package Manager does not understand proxy authentication and you need to change its configuration to use your local proxy server (Fiddler) to take care of authentication. The configuration file is located in

%USERPROFILE%\AppData\Roaming\NuGet\NuGet.Config

<configuration>
  <config>
    <add key="http_proxy" value="http://localhost:8888" />
  </config>
</configuration>

Node Package Manager (NPM)

At this moment Nuget Package Manager does not understand proxy authentication and you need to change its configuration to use your local proxy server (Fiddler) to take care of authentication.Run the following command to know if your NPM is using any proxy.

Run the following command to know your current proxy setting (if any).

npm config get proxy

To set Fiddler as your proxy setting use the following command.

npm config set proxy http://localhost:8888

You have the possibility to point to your corporate proxy server using the following syntax.

npm config set proxy http://{domain\username-url-encoded}:{password-url-encoded}@{proxy-domain-name}:{port}

But keep in mind that if you directly point to your corporate proxy, every time your password changes you need to run the above command again to update the setting.

Side: To URL encode your username or password you can use encodeURIComponent in your browser’s Console. For example:

>> encodeURIComponent('domain\\username')
"domain%5Cusername"
>> encodeURIComponent("P@ssw0rd!")
"P%40ssw0rd!"

Visual Studio’s Task Runner (NPM in Visual Studio)

Whatever I explained about configuring NPM’s proxy setting previously is still applicable here, but you need to keep in mind that Visual Studio uses its own local NPM and not the one you might have installed globally. This means that you need to run the above commands in “Developer Command Prompt for VS” and not in a standard command prompt.

Visual Studio Code

VS Code in its more recent versions supports proxy authentication and it can even help its extensions to use its proxy settings, but some extensions (e.g. NPM) still resist it (pun intended) and you might need to configure them independently. If for any reason you need to manualy set VS Code’s proxy please refer to: https://code.visualstudio.com/docs/setup/network

Git

Starting from version 1.7.10, Git supports NTLM proxy authentication. You can find the commit here. Although you still need to instruct Git to use your proxy, because it does not detect it from your OS. To do so, you can point to your proxy server’s URL and Git will do the rest. The following bash command is setting the proxy URL to Fiddler’s default URL, but you can use your company’s proxy server too. You can either point to Fiddler to take care of proxy authentication using the following command.

$ git config --global http.proxy http://localhost:8888

Or directly point to your corporate proxy and include your username. Git can remember your credentials using Windows Credential Manager, but you need to make sure that your Git client is configured to use the credential manager and you are using v. 2.8.0 or higher.

$ git config --global http.https://github.axa.com.proxy http://[proxyuser@]<proxyhost>:<port>

To make sure Git is using Windows Credential Manager run the following command.

$ git config --global credential.helper wincred
How to fix proxy authentication issues in your development environment

Development behind corporate proxy + authentication

Developing in companies that have proxy servers for developers can be frustrating in this age when every tool needs access to online resources and even parts of software development life cycle are cloud based. Proxy servers that require NTLM authentication just add to that frustration. NTLM is developed by Microsoft but many applications built by Microsoft do not support it or require some configuration and in worst cases some hacking to make it work. Below is a list of some the tools that developers might be using on a daily basis and what you need to do to make them connect via NTLM proxy. I keep adding more to the list as I encounter them.

  • Visual Studio Code (VSCode)
  • NPM
  • Visual Studio, Web Platform Installer and other .NET Applications

Visual Studio Code (VSCode)

VSCode 1.15 and up now supports NTLM proxy (finally Microsoft supported its own authentication protocol).

NPM

For NPM you have two options. Either to send proxy address and credentials in every single command you run or to set them in the global configuration of NPM. I recommend the former because it is more secure.

Set proxy in every command

When calling NPM command you can always use --proxy switch to set proxy for each command. The syntax for using this switch is the following.

--proxy username:password@proxyaddress:port

For example to use myproxy:8080 as proxy address and my-domain\reza as username and P@ssw0rd as password when calling the install command you can type the following.

npm install --proxy http://my-domain%5Creza:P%40ssw0rd@myproxy:8080

Please note that both username and password are URL encoded. You can use the following command in your browser’s developer tools to encode them.

encodeURI('my-domain\\reza')
encodeURI('P@ssw0rd')

Set proxy in NPM configuration

To set the proxy in the global configuration of NPM you need use the same format as above for sending the proxy address, username and password and use npm config set to store it in the configuration. For example to set the proxy address to myproxy:8080 and username to my-domain\reza and password to P@ssw0rd you can use the following command.

npm config set proxy http://my-domain%5Creza:P%40ssword@myproxy:8080

Visual Studio, Web Platform Installer and other .NET applications

To set the proxy for pretty much any .NET application, you need to put the following in the configuration file of that application.

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

For Visual Studio I suggest also enabling IPV6 if the above configuration did not work as suggested by some other developers.

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

For executable files the configuration file is named the same as executable’s file name but with .exe.config extension. For Visual Studio it is called devenv.exe.config and for Web Platform Installer it is WebPlatformInstaller.exe.config.

Postman

At the moment Postman (v7.36.1) does not support NTLM authentication and the only best way that you can make it work is by using Fiddler. Here is what you need to do, step by step:

  1. Install Fiddler and run it.
  2. Make sure Rules > Automatically Authenticate is selected. This will enable Fiddler to authenticate on behalf of Postman with your current user account.
  3. * In Postman, go to File > Settings and then Proxy and turn on Global Proxy Configuration
  4. For Proxy Type select both HTTP and HTTPS
  5. For the Proxy Server, use 127.0.0.1:8888 (If you you have changed the default port that Fiddler is listening on you will need to change it here as well).
  6. ** In Fiddler, go to Tools > Options... and then in HTTP tab, select Capture HTTPS CONNECTs and Decrypt HTTPS traffic and install the certificate when prompted.
  7. In Postman go to File > Settings > General, turn off SSLS certificate verification. You need to do this because currently, Postman does not support intermediate proxies.

* In step 6, instead of using Global Proxy Configuration you may also use Use System Proxy, but in that case you need to make sure in Fiddler, Capture Traffic is selected under File menu. This way Fiddler will capture all the HTTP traffic by setting Windows Proxy settings.

** You won’t need to do step 6 and 7 if you won’t be working with HTTPS URLs.

Development behind corporate proxy + authentication

Disabling Security warning for Attach to process in Visual Studio 2010, 2013 and 2015

You probably have already suffered from the pain of having to click one more time when attaching visual studio’s debugger to a process. As developers we all have the obsession to be more productive and everything that comes in the way is a bummer. I should have shared this little secret before, but … I forgot.

You know this message box, right?

attach-security-warning1

Now when a colleague sent me a link to a blog post that explains how to change a registry key to disable the security warning in Visual Studio when attaching to processes, I decided to write a little “.reg” file to make it even easier for you. This warning is there to warn you when you are attaching the debugger to a process and that process is (that are running with different accounts than the one running Visual Studio)  The reg file works for Visual Studio 2010, 2013 and 2015 no matter which edition. You can view / download it from here:

Disabling Security warning for Attach to process in Visual Studio 2010, 2013 and 2015

Per developer web.config files using out-of-the-box Visual Studio functionality

It might be a repetitive subject and some might argue that it’s even best to have identical web.config files for all developer. But, the fact it sometimes it’s inevitable! you are not always building software from scratch. It might be an extension to a huge software that contains per-machine keys and configurations. Unfortunately there are many blog posts here and there that suggest using batch files and methods that are more like a hack. Here I’m going to explain how to use the out-of-the-box functionality in Visual Studio without any external tool or hack.

If you already know how those two web.debug.config and web.release.config files work you’ll get the idea. Basically they are a kind of Xslt transformation that are selected based on the current configuration (web.($configuration).config) and we want the same thing but based on current username (web.($Username).config). To learn how to use web.config transformations and its syntax visit “http://go.microsoft.com/fwlink/?LinkId=125889

And here is the recipe:

  1. Right-click over the project name in Solution Explorer and select “Add \ New Item…”
  2. Select XML File under Data category and give it a name in the following pattern web.{username}.config (e.g. web.reza.config).
  3. Copy-paste the content of web.debug.config to this new file (i.e. web.{username}.config) to use as a starting point and override the settings as you need. If you don’t feel comfortable with the transformation syntax, take a look at this page. It’s fairly easy.

Here is an example to override the <machineKey> attributes.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <machineKey xdt:Transform="SetAttributes" validationKey="EFEF01678000A361AADF4E01DB5AD356C91111E781660310" decryptionKey="6EF12ECA1A36ACAC4D08212E9FA8F34B1919A3DD818B8E0F" validation="SHA1" />
</configuration>
  1. Save the file.
  2. Right-click over the project name in Solution Explorer and select Unload Project.
  3. Right-click again over the project name and this time select Edit {projectfilename}.
  4. At the end of the file, right before </Project>, paste the following piece of XML (don’t worry I will explain later).
<Target Name="AfterBuild" Condition="Exists('web.$(USERNAME).config')">
    <Copy SourceFiles="web.config" DestinationFiles="obj\$(Configuration)\tempweb.config" />
    <TransformXml Source="obj\$(Configuration)\tempweb.config" Transform="web.$(USERNAME).config" Destination="obj\$(Configuration)\tempweb2.config" />
    <ReadLinesFromFile File="obj\$(Configuration)\tempweb2.config">
      <Output TaskParameter="Lines" ItemName="TransformedWebConfig" />
    </ReadLinesFromFile>
    <ReadLinesFromFile File="web.config">
      <Output TaskParameter="Lines" ItemName="UnTransformedWebConfig" />
    </ReadLinesFromFile>
    <Copy Condition=" @(UnTransformedWebConfig) != @(TransformedWebConfig) " SourceFiles="obj\$(Configuration)\tempweb2.config" DestinationFiles="web.config" OverwriteReadOnlyFiles="True" />
  </Target>
  1. Save the project file.
  2. Right-click on the project file again and select Reload Project this time.
  3. Build and project and check the result.

And now the explanation. Basically what we did was to add an AfterBuild process (you can also use a BeforeBuild) and set a condition for it to only run when there is web.{username}.config file in the project’s root. It means that if there is no such file for the current developer, it will be skipped. Within the process we have 5 actions that run in the order that is written:

  • <Copy> makes a copy of web.config file to “obj\($configuration)” folder with the name “tempweb.config”. The value of $Configuration depends on the build configuration currently selected in your Visual Studio (e.g. Release or Debug).
  • <TransformXml> runs the transformation to override developer specific values in the tempweb.config file and generates another file (tempweb2.config).
  • The two <ReadLinesFromFile> actions load the content of tempweb2.config and original web.config file into two different variables.
  • The last <Copy> replaces the original web.config only if there is any difference between the generated file and the original (Condition="@(UnTransformedWebConfig) != @(TransformedWebConfig)").
Per developer web.config files using out-of-the-box Visual Studio functionality