Skip to content

Access Visual Studio localhost on host from guest virtual machine

Working with multiple virtual machine boxes is very common now days in software development. Mostly indi developers use virtual machines to separate different technology stacks. Some use one VM per project basis. And eventually it is needed to communicate from virtual machine guest OS to host OS.

Typical scenarios are like accessing guest machine’s localhost from guest OS or vice versa. Recently I faced similar situation, where I wanted to access my localhost of host OS from guest. You can do it very simple, just use host OS IP address and you can instantly access. But the problem was, I was using Visual Studio on host OS. And it was not allowing access by IP. So, I did some tweaks and decided to write this blog, so that I can follow these steps next time, if needed.

This is simply very easy.

First open the root folder of your visual studio solution in file explorer. Make sure hidden folders are set to be visible. There you will find a hidden folder named “.vs”. Inside this folder there is config folder and inside that you will find a file named applicationhost.config. Open this file and search for binding. There you will find existing binding for the app. You need to add the local IP of your machine here. Something like below screenshot.

You can see I have added the host OS local IP and port here in bindings. In my case IP is 192.168.0.102 and port is 57663. You can get it by opening command line and using ipconfig command.

Now when you will run it, visual studio will give error. To fix it, you will need to open visual studio as administrator and run the application.

In the last you will need to open the port this application is running on, in firewall setting. To do that just create a new inbound rule with domain, private and public access. If you don’t want to give public access then you will need to create a security group, I will add steps for that later sometime here.

Now you can go and access the host OS localhost like:

http://192.168.0.102: 57663

Have fun.

Be First to Comment

Leave a Reply

Your email address will not be published.