This post originated from an RSS feed registered with .NET Buzz
by Peter G Provost.
Original Post: Using Class Libraries Projects as Web Project in VS.NET
Feed Title: Peter Provost's Geek Noise
Feed URL: /error.aspx?aspxerrorpath=/Rss.aspx
Feed Description: Technology news, development articles, Microsoft .NET, and other stuff...
Richard Lawrence asks
in the comments of my post Create the Solution Before Adding Projects
Where can I find more information about making web projects work as Class Libraries?
I've looked around on your site and Brad's, but no luck. Thanks.
Since as far as the compiler and the runtime are concerned there is no difference
between web projects and assemblies, all you really have to do it convince VS.NET
to behave.
Here are the steps I follow. This process is far from ideal, but it works for me.
First you need to setup VS.NET to allow you to add web files to class library projects:
Open the file WebProjectItems.vsdir in a text editor. (This file is typically
installed in C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\WebProjectItems)
Open the file LocalProjectItems.vsdir in a text editor. (This file is typically
installed in C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\WebProjectItems)
Copy the following lines from WebProjectItems.vsdir to LocalProjectItems.vsdir.
(Note: I don't know if the GUIDs and IDs are different on different installs. If not
you can just copy these.)
Once you have done that, you can create a project.
Open Visual Studio and create a Class Library project.
Add a reference to System.Web
Open IIS Manager
Add a New Virtual Directory to your Default Web. I like to name mine the same
thing as my Web (Class Library) Project.
Browse to your project folder and click OK.
From File Explorer, give the IUSR_MACHINENAME and ASP.NET accounts read and execute
right on the files and folders in the project.
In the project settings for your project, set the Configuration drop-down list
to All Configurations. Set the following settings:
Build:
Output Path: bin\
Debugging:
Enable ASP.NET Debugging: True
Debug Mode: URL
Start URL: The url you setup for the virtual directory
Build your project.
Debugging your project is done by attaching to the IE and ASP.NET_WP processes.
Start your project by pressing F5. This will launch IE and attach to the running IE
instance.
Once the web browser is up, choose "Processes..." from the Debug Menu.
Check the "Show System Processes" checkbox.
Select aspnet_wp.exe from the list and click Attach.
In the "Attach to Process" dialog, check "Common Language Runtime" and click OK.
Close the "Processes" dialog.
Set breakpoints and start debugging.
That's it. A few things to note:
I'm pretty sure you could dig through the project config files in VS.NET and create
a new project template that does all of the project setup steps. This exercise is
left for the reader.
Your project will not have a Global.asax or a web.config file. Add them if you need
them.
I don't know how to add "Web Form" to the "Add..." context menu in Solution Explorer.
Anyone?
I would love to have better way of debugging.
Please leave comments if you know how to deal with these issues or if you know of
a better way of doing this.