Moving .NET Web Projects

Tom · Friday, Mar 23, 2007, 7:26 PM · Krehbiel Tech

I've had some annoying problems opening other people's ASP.NET web projects from Visual SourceSafe.  By default, it sets up the local IIS directory in C:\Inetpub\wwwroot regardless of the location of the solution directory.  I prefer setting up a virtual directory that points to the actual project location, which for me is on the D: drive.  After a bunch of trial and error and some Google searches, I've found the following steps work somewhat reliably.

Let's assume we're trying to open a solution named "Beatles" which contains a web project named "PennyLane."  We want to put the solution in D:\Projects.

  • Get the solution from source control and place it in the desired location (eg. D:\Projects\Beatles).  I typically do this with Get Latest Version in the SourceSafe explorer, but you can probably do this inside Visual Studio as well.
  • If there is a .suo file in the solution directory, delete it.
  • Load the solution into Visual Studio (eg. Beatles.sln).
  • Visual Studio will prompt you to Enter a Working Copy Location for the web project.  The default location will be something like http://localhost/PennyLane created in C:\Inetpub\wwwroot\PennyLane.  Cancel this dialog.
  • You'll then be asked if you're sure.  Click "Skip loading listed projects."
  • You may then get a message that loading from source control failed.
  • The web project (eg. PennyLane) will be listed in the solution as "unavailable."
  • Remove the web project from the solution.
  • You'll be prompted to check out the solution file from source control.  Go ahead and do that.
  • Run Internet Information Services (IIS) from Administrative Tools.
  • Navigate to Default Web Site.
  • You may see the name of the web project (eg. PennyLane) already in the directory list.  Visual Studio made that for you, even though you told it to cancel that step above.  Delete the directory.
  • Create a new virtual directory.  Click Next to start the wizard.
  • Enter your web project name as the alias (eg. PennyLane).  (Actually, you can enter any name you want here.)  Click Next.
  • Enter the directory where the web project file resides (eg. D:\Projects\Beatles\PennyLane).  Click Next.
  • Check the "Browse" box on the Access Permissions page.  Click Next.
  • Finish the wizard.
  • Go back to Visual Studio.
  • Either on the File menu, or by right-clicking the solution, select Add Existing Project From Web.
  • Enter the localhost URL to the virtual directory created in IIS above (eg. http://localhost/PennyLane).
  • Select the project filename from the list (eg. PennyLane.csproj).  (If you aren't able to see the project file, you may have forgotten to enable the "Browse" permission.)
  • At this point, one of two things might happen:
    • Visual Studio may tell you it can't load from source control.  In that case, save and close the (possibly empty) solution, then re-load it.  Retry adding the project from the web, and it should work.
    • Visual Studio may also ask you to change the file share location of the project. In that case, navigate again to the directory that contains the project (eg. D:\Projects\Beatles\PennyLane).
    • Update: You may also be told that the web project can't be loaded from the specified path. If so, make sure the solution's .suo file is really deleted.
  • Load up the SourceSafe explorer and make sure the working directory of the web project is set to the project directory (eg. D:\Projects\Beatles\PennyLane), not C:\Inetpub\wwwroot.
  • At this point you should also be able to go back to IIS and turn off the "Browse" permission for the virtual directory.

I freely admit it's a pain to do all of that.  You may choose instead to accept the default location of C:\Inetpub\wwwroot that VS uses for web projects.  If you do, don't forget that you will have TWO copies of your web project on your system.  The "active" copy will reside in C:\Inetpub\wwwroot, but there might also be another copy in the same directory with the solution.  Don't be fooled!  If you need to edit or change web project files outside of Visual Studio, make sure you go to C:\Inetpub\wwwroot and NOT the directory where the solution file resides! 

Cross-posted to http://krehbieltech.blogspot.com/2007/03/moving-net-web-projects.html

Tags: ASP.NET(3)

Comments are no longer being accepted on this post. To minimize the effort of dealing with comment spam, comments are automatically closed on older posts. The administrator may also close comments at his discretion.