7/27/2004

How to make VS.Net not depend on IIS

Filed under: General — russell @ 4:00 am

I found a good source for how to make Visual Studio web projects without "binding" them to IIS. When a web project is created in .Net it hard codes the pathing and solution to IIS virtual web. WHile certainly nice for deploying it limits the flexibility of moving the project aorund. I found a source for how to stop this by using a class library project. Reference prepared by Fritz Onion.

ASP.NET Applications without Web Projects

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:
change:
Project("") = "WebApplication133", "http://localhost/WebApplication133/WebApplication133.csproj", ""

to:
Project("") = "WebApplication133", "WebApplication133.csproj", ""

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:
http://localhost/testproj/webform1.aspx

*********************************
One caveat, it was a little unclear about how you create new VB Web Projects under this scenario, so here is a briefing:

follow the instructions in Fritz's document for adding project wizards.

1. Create a New Empty VB Project
2. Add a WebForm and a Web.Config
3. Open IS Manager and either point your Default Web Site's home directory to this folder, or make a Virtual Directory pointing to it.
4. Right-Click your Project and select Properties, then Configuration Properties/Debugging
5. Change Start Action to Start URL instead of Start Project and use the URL (not the file location) of your start page, i.e. http://localhost/webform1.aspx
6. enable ASP.NET debugging
7. Now go to Common Properties, Change the output type from Windows Application to Class Library (feel free to change your root namespaces and Assembly name now that you CAN), apply the settings and close the properties dialog

Hit Start and enjoy your new ability to debug flexibility :-)

HELPFUL URLS:
http://www.peterprovost.org/archive/2003/08/15/734.aspx
http://blog.steeleprice.net/archive/2003/11/09/134.aspx
http://www.pluralsight.com/fritz/Samples/aspdotnet_without_web_projects.htm


No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Couldn't find your convert utility. Check that you have ImageMagick installed.