Friday, March 13, 2009

Browse with Firefox, Debug with Internet Explorer

NOTE: I originally published this entry on my company blog here.

As a .NET developer, it is a necessity to debug my work in Internet Explorer. However, for my day-to-day web borwsing, I prefer to use "something else".  Lately, my something else has been Google Chrome, but I'm also a big fan of Firefox.  The problem is that, by default, if I change my default to be Chrome, then when you hit F5 to debug in Visual Studio, then Chrome is what gets launched for the debugging sessions.  For basic stuff, this is fine, but it's not ideal for me, particularly when I want to be able to debug client-side script from within Visual Studio.


I have dealing with this for a long time basically by not dealing with it at all...  That is, I have left Internet Explorer as my defaut browser and just launched Chrome for my routine browsing.  This is OK, but then whenever there is a link in an email, or a blog post (I use Outlook for RSS feeds), then Internet Explorer gets launched to handle it.  Not what I want.


Well, I finally got irritated enough by it this morning to hit Google and see what I could find.  It turns out the answer is pretty simple, but differs a little bit depending on whether the project is a Web Site project or a Web Application project.

Web Application Project

In Visual Studio, if you go right click on the project in the Solution Explorer, and go to Project Properties, the on the Web tab you can configure a custom Start Action, rather than just launching using the default browser.  Under Start Action, you would select "Start External Program", and use "C:\Program Files\Internet Explorer\iexplore.exe" to launch Internet Explorer.  Then, for "Command Line Arguments", you have to supply the URL of the start page.  In my example, this is "http://localhost:60669/Default.aspx".  The port number is required because I have also elected to use the Visual Studio Development Server, which can be seen in the next section, "Server".  The only thing that has to be changed there is that instead of allowing Visual Studio to randomly assign a port number, you must pick one.


Here is a screenshot of some example settings that work for a project of mine.



Web Site Project

If the project in question was created as a Web Site Project, then the configuration is slightly different.  First, click on the project in the Solution Explorer, and the in the Properties pane, change the Use Dynamic Ports property to False.  This will enable editing of the Port number property.  Set the port number to some fairly high numberl I used 60668 in my example.  Make note of what is in the Virtual path property, because you will need it for the next step.  (You can also change this virtual path if you wish).

Next, right-click on the project in the Solution Explorer and select Property Pages.  Under "Start Options", choose "Start External Program:"  The executable (C:\Program Files\Internet Explorer\iexplore.exe) and command-line arguments (http://localhost:60668/Website1/Default.aspx) arethe same as for Web Application projects.   The command-line arguments need to use the port number and Virtual path from the previous step.

Here are a couple of screenshots that work for my sample project.