.Net ramblings
# Sunday, 19 September 2004
Problems using Visual Studio.Net and Visual Source Safe with Web Projects

If you get annoyed at Visual Source Safe's complications with using asp.net web projects, and integrating them with Visual Studio.Net, an increasingly popular approach is to use 'class library' projects instead of web projects.  (Of course, this problem will disappear with Whidbey but i'm still using VS 2003).  A web project compiles a dll / class library anyway, and VS doesn't have to interact with IIS to load the project.  It isn't hard to set up but it does require careful instructions to be followed.  A guy called Fritz Onion prepared the content below:

This is copied/pasted here in case Fritz's link changes or disappears. The original content is available from:

Reference prepared by Fritz Onion

The Web Project wizard in Visual Studio .NET is convenient for creating quick ASP.NET applications on your local machine, but in an effort to simplify your life, it also makes many decisions for you that are difficult to change if you need more flexibility. My biggest pet peeve with Web Projects is that you cannot even open a .sln file if the virtual directory mapping in IIS is not set up correctly. I also dislike the way it places .sln and .csproj | .vbproj files in a separate location from the actual source files (I understand that this is necessary to allow application creation directly on a server, but I never deploy that way).

As a result, most of my web projects are created as standard class library projects. Unfortunately this means that you don't get the nice Web component wizards (like WebForms and UserControls). However, with a little tweaking, you can have it all.  I have prepared this document describing how to enable these wizards in class library projects (thanks to Dan Sullivan for pointing out how to do this), as well as how to convert existing Web Projects to class library projects and still keep the nice integrated debugging.

To enable Web wizards in a class library project:

In a directory called

C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\LocalProjectItems

is a file callled localprojectitems.vsdir.

Likewise in a directory

C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\WebProjectItems

is a file called webprojectitems.vsdir.

If open the second file with notepad you can figure out the lines to copy to the first file to be able to add the usual files you need to create an aspx page or web service to a class lib project.

Once you have copied these thing open VS, open a class lib and go to add new item and you will see these additional file types available.

To set the output of a class library project to go to a /bin directory of your choosing:

1. Right-click on the project and select properties
2. Set Configuration to 'All Configurations' to affect both debug and release builds
3. Under configuration properties/build set the OutputPath to the /bin directory

To convert an existing web project into a class library project:

1. Open the .sln file in a text editor, and change the reference to the project from an http://... reference to a simple reference to the .csproj (or .vbproj) filename. For example:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication133", "http://localhost/WebApplication133/WebApplication133.csproj", "{39CB37A5-F735-4684-B5DA-DD355B683090}"

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication133", "WebApplication133.csproj", "{39CB37A5-F735-4684-B5DA-DD355B683090}"

2. If there is one, delete the .webinfo file
3. Open the .csproj (or .vbproj) file and change the ProjectType attribute from "Web" to "Local"

To set up a class library project to run a browser when you debug it:

1. Right-click on the project in the solution explorer and select properties
2. Under Configuration Properties/Debugging, change Debug Mode from 'Project' to 'URL'
3. Hit Apply
4. In the Start URL field, enter the complete url to the page you want to hit to debug, like:

Sunday, 19 September 2004 23:32:44 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  .Net General