Saturday, May 07, 2011

Creation of the virtual directory failed

On attempting to open project in VS2008/2010, I got the following message:
The local IIS URL http://localhost/MyApp specified for Web project DemoWebsite has not been configured. In order to open this project the virtual directory needs to be configured. Would you like to create the virtual directory now?

On clicking yes, I got the following error:

Creation of the virtual directory http://localhost/MyApp failed with the error: The URL 'http://localhost/' is already mapped to a different folder location.

The rest of the solution opened all right, but the above project did not; it was marked as unavailable.

Solution (I am working on a Vista machine):
Close VS.
Start IIS management
look in the in the localhost website and delete MyApp (your visual studio wil recreate it for you anyway).
Open the solution with VS2008/2010 and answer yes when asked to create the virtual directory.

Another solution to this problem I found on Neil Pullinger's blog
Creation of the virtual directory failed

But the Solution is for the main localhost site http://localhost, not for http://localhost/MyApp.
Here is the tekst of his solution:

... I right-clicked the project node in the solution explorer and selected the option to edit the project (.csproj) file. Near the bottom of the file, I found the following:

http://localhost/

I edited this entry to add a virtual directory:

http://localhost/myapp

Having saved the change, I then right-clicked the project node in the solution explorer again and reloaded the project. When I was prompted to create the virtual directory again, the creation was successful and the project checked out. The virtual directory is created under the running web site in IIS (on Windows XP).