21

I have a app which is under source control (TFS 2012 also) on c:\Dev\MyApp\Main.

Because im developing a new feature I decided to open a branch on c:\Dev\MyApp\BranchNewFeature.

I developed and when I decided that it was time to test it was like i hadn't done any changes at all. I hit F5 and i see the baseline version of the app... Looking into it I noticed a very curious fact: When i check IIS Express the "launch path" for the applications is the old one (c:\Dev\MyApp\Main).

Can anyone help me make IIS Express point to the new path? (C:\Dev\MyApp\BranchNewFeature)

7
  • Did you try closing IIS express and starting it again? Commented Apr 4, 2013 at 18:20
  • @cheesemacfly yes! I even had restarted the whole machine...
    – Leonardo
    Commented Apr 4, 2013 at 18:51
  • 1
    Did you change anything in C:\Users\your_name\Documents\IISExpress\config\applicationhost.config? Commented Apr 4, 2013 at 19:02
  • 1
    @cheesemacfly no! i was looking into that file and all my web apps are there! and it's pointing to the wrong file!
    – Leonardo
    Commented Apr 4, 2013 at 19:09
  • Well then I guess if you put the right path here it should work! Commented Apr 4, 2013 at 19:18

7 Answers 7

24

I ran into the same issue. To fix it, I used cheesemacfly's suggestion, to update C:\Users\%USERNAME%\Documents\IISExpress\config\applicationhost.config to point to the new directory.

The obvious downside with this solution is that you need to do this repeatedly if you plan on switching between your new branches often. Seems like a bug in VS2012...

4
  • 16
    Reproduces in VS 2013 also
    – EvAlex
    Commented Dec 17, 2013 at 8:36
  • This is not a answer, but rather a workaround... VS should launch it as expected...
    – Leonardo
    Commented May 28, 2014 at 16:59
  • 3
    I solved this problem by right-clicking one of the projects in Visual Studio, and under Web changed the port of Project Url (they were the same). I then renamed my applicationhost.config file to applicationhost_bak.config, and restarted Visual Studio. Commented Jul 7, 2014 at 8:27
  • Aargh! i wasted 4 hours today tracking down this problem. Thanks for the advice. I changed my paths in the config and now everything works fine. Commented Apr 20, 2016 at 20:17
17

Restarting VS seems to fix this problem. This is just an alternative solution, just as its a norm with all Windows products - close and restart, and boom it'll work!

Here's what happened: I faced the same problem after I worked on a web project in a branch using VS2013. As Chris Gillum mentioned above, I had the applicationhost.config open while I restarted VS, and the file got auto-refreshed with the correct path. So, this definitely seems to be a bug in Visual Studio.

UPDATE:

I've seen this issue numerous times since I posted this answer. And I've found an alternative to restarting VS. Here's what I do now:

  1. Right click IISExpress Icon and click on "Show all Applications"
  2. Select the Site Name from the list
  3. Click (and open) the Config file
  4. Search for and fix the physical path to your workspace under the following section:

    <sites>
        <site name="MyWebSite" id="XXX">
            <virtualDirectory path="/" physicalPath="FIX_THIS_PATH" />
        </site>
    <sites>
    

IISExpress will automatically refresh the site, and you do not need to restart VS. Hope this helps someone.

2
  • 2
    My issue is that I had both branches open at the same time. After fixing the issue in MAIN and closing it, DEV ran the wrong code. A simple restart of VS2013 with the DEV project fixed the issue. Thanks...
    – ShaneBlake
    Commented Apr 16, 2014 at 20:42
  • 1
    This is a good answer because IIS Express has changed a bit since the original question was posted. In VS 2015 the config files for IIS Express are stored in the .vs folder in the solution folder.
    – trevorc
    Commented Nov 9, 2015 at 18:21
3

In case you get here searching for the same issue in Visual Studio 2015, the applicationhost.config file has moved to a hidden folder: $SolutionDirectory/.vs/config.

2

When you open a Visual Studio solution that contains an IISExpress web project, the applicationHost.config <site> element configuration is updated. If you then open a solution for a separate branch, it's possible that the <site> configuration will be overwritten to point to that separate branch.

For example, let's say you have two branches of a solution containing a web project configured to use IISExpress on port 4000. When you open the solution for Branch1, the applicationHost.config will be updated with a <site> element registering a site at localhost:4000 pointing to the folder for Branch1. When you 'Start Debugging' your solution, your browser opens localhost:4000 and everything works just fine.

If you then open the solution for Branch2, the applicationHost.config will be modified again, overriding the <site> element so that localhost:4000 now instead points at Branch2. Now, if you 'Start Debugging' in either the open Branch1 solution or the open Branch2 solution, localhost:4000 will be pointing to Branch2, since that's what's in the applicationHost.config file.

To work around this issue, configure the two branches to use different ports and then Visual Studio will manage two separate applicationHost.config <site> elements, one for each branch. You'll need to remember to configure a new port number each time you create a new branch.

1

I had a similar situation where I had copied a project. After running the project it displayed the original project in the browser rather than my copied, edited version. My solution was to remove all the effected sites from the config file:

C:\Users\%USERNAME%\Documents\IISExpress\config\applicationhost.config

I then had to right click the project in Visual Studio, click Properties then click the Web tab, on this tab I changed the port specified in the Project Url and saved. Visual Studio then asked if I wanted to add the project back to the application host configuration file. I clicked yes and run the project, suddenly all was fine.

My particular problem was not a bug in Visual Studio but rather a configuration mismatch.

1

I had a similar situation, and was looking for an answer, when I found this article. I thought about applying this fixed, but felt it was a lot of effort every time you need to branch or merge again.

I did a little more digging, and I believe I found an easier fix. I found that in Visual Studio 2013 if you open the Properties of the project, and click on the Web option, you will see a Servers section with a button 'Create Virtual Directory' in it.

If you click this button it will prompt you with a question about it pointing to a different directory then the project is in, would like to fix it. When you click yes it makes the fix for you, and when you debug now it will pull from the correct location.

0

In VS 2015, I didn't have to edit the config file directly. I opened the branched project and went to Properties page under the Project. Go to the Web tab and edit Servers > Project URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.