27

I have a website project using Visual Studio 2013, and each time I open it, it keeps adding a new entry for the website project in applicationHost.config. I use IISExpress for my development, however I always create a custom entry to provide some specifics and I have it configured to use port 80, so I would like to not have Visual Studio make any modifications to this file.

I have gone into Tools > Options > Web Projects and unchecked "Use the 64 bit version of IIS Express for web sites and projects", closed the solution, removed the entry from applicationHost.config and re-opened the project in Visual Studio, however it still continues to add an entry to applicationHost.config and name my website project whatever that entry is named.

Is there a way to disconnect Visual Studio entirely from IISExpress? I like using it, but I want to control that service and configuration myself.

Kyle B.
  • 5,737
  • 6
  • 39
  • 57

6 Answers6

23

Inside the bindings section of the site section, create a new binding in addition to the localhost version like so:

 <bindings>
     <binding protocol="http" bindingInformation="*:21232:localhost" />
     <binding protocol="http" bindingInformation="*:21232:*" />
 </bindings>

After having both lines, VS stopped making new site sections.

Stuart Allen
  • 691
  • 6
  • 15
  • 3
    I think I've tracked down what is going on that makes this work. My goal was to make my site accessible over my local network, so I would edit the tag to change "\*:port:localhost" to "\*:port:*" Visual Studio, on building the web application project, was searching for a binding with the project name that contained "*:port:localhost", and if it could not find one, then every time it built the project it would add a new entry. Your change thus makes VS keep the correct settings after rebuild. – dhakim Feb 25 '15 at 16:08
  • This works in vs2015. Expanding on what dhakim said, it looks like its trying to match up the bindings to the "Project Url" in the "Web" section under properties – bgura Aug 10 '17 at 15:27
  • 1
    you helped me too! Thanks ;-) – Yisroel M. Olewski Jul 03 '19 at 12:26
4

How to: Specify a Port for the Development Server

I just tried out the method described in the above msdn article to change the port IIS express uses (didn't try 80 though).

  1. right click the website in solution explorer, remove (won't delete files)
  2. edit the applicationHost.config file, change the binding
  3. "add existing web site" in Visual Studio (point to the folder of site you previously removed)

At that point it doesn't seem to create a new entry in applicationHost.config, and uses the new port.

Anssssss
  • 3,087
  • 31
  • 40
  • This seemed promising, however each time I selected an option from the "Local IIS" pool as noted in the MSDN article, it tries to add the site from Id="1" regardless of which one I specified. It's almost as if it's a bug in Visual Studio. It may be because all sites configured in the element use port 80, I'm not sure. Additionally, but I didn't get too far into it, there may be an issue if the website was under source control (which it is), trying to re-add it. – Kyle B. Nov 01 '13 at 12:50
  • I didn't follow the steps about the "Local IIS" tab when I was trying it. To be clear, I was able to change the port number this way and no new entry was created in applicationHost.config, but I was setting the port to things like 55456, nothing special like port 80. When I tried it with 80, I got this error: Error opening web http://localhost. The site for the URL 'http://localhost' exists on both the local IIS web server and the IIS Express web server. You need to edit the 'applicationhost.config' file to change the port number in use by IIS Express. – Anssssss Nov 01 '13 at 13:58
  • Same issue. Even when adding an existing site from the file system, it attempts to add the site record with Id="1" in applicationHost.config, despite explicity giving it the path to the other web project (which is like Id="8" I believe). I honestly feel this should not be expected behavior and will submit a bug report to Microsoft. – Kyle B. Nov 01 '13 at 14:07
  • https://connect.microsoft.com/VisualStudio/feedback/details/807429/adding-an-existing-website-to-a-solution-does-not-insert-the-correct-project-as-noted-in-the-file-path – Kyle B. Nov 01 '13 at 14:15
3

We have the same problem here. Two days googling for a solution without success. The only solution until now is to add the website to the solution using the Local IIS option.

Andre RB
  • 306
  • 4
  • 7
1

I ran into this trouble when I was switching from one TFS workspace to another while experimenting with VS2013. I'd updated to VS2013 from VS2012 in a new workspace, then when I was done and committed the changes, I got the latest in my original workspace and began to use it there with VS2013. Every time I loaded my web project I got the message about it editing my project file, and every time it did, it screwed up the settings.

Here's how I fixed it, after trying the other answers here. A bad .csproj.user file was the problem. I do not use this file, generally, as I have the "Apply server settings to all users (store in project file)" checkbox in the Web properties checked. But I'd used it in the past. Deleting this file, or updating it so that the settings match those I've set in the project file (i.e. setting the port, whether to use IISExpress, etc.) fixed it. I can now load my project without visual studio making (the wrong) edits to my project file every time I load.

rrreee
  • 753
  • 1
  • 6
  • 20
  • I had the same issue where VS was constantly resetting the SSL port every time I opened the project. In the end it turned out that the settings in the csproj.user file were causing the issue. I deleted the file and the issue was resolved. – Kevin Brady Oct 31 '16 at 15:34
0

In the project properties, I see a "Web" tab, which contains a "Servers" section that has a dropdown where you can select from the following:

  • IIS Express
  • Local IIS
  • External Host

I believe selecting "Local IIS" is the option you need.

Anssssss
  • 3,087
  • 31
  • 40
  • This is a 'website' project, not a 'web application' project. There is no 'web' tab inside the project properties. I wish it were that simple. – Kyle B. Oct 30 '13 at 18:10
0

If you don't want to use a local development server, you can attach to an IIS process on a local machine very easily.

There's a way to set the build output location for debug in the properties (right-click project in solution explorer and choose 'properties). If you want to do this easily the first time with no extra setup, just copy your debug build's output to your website folder that you configured in IIS.

Next, ensure you can hit the IIS site. If so, go back to Visual Studio and go to the Debug-> Attach to Process menu item. Choose 'w3wp.exe' out of the list (you may have to check 'view all processes'). You should now be able to hit breakpoints in VS.

However, you should also be able to use IIS Express with a specific port, as @Anssssss said.

ps2goat
  • 8,067
  • 1
  • 35
  • 68