How to: Hack a Class Library Project into a Web Application Project
Posted
Friday, February 22, 2008 2:09 PM
by
CoreyRoth
Kind of a weird tip here, but I have ran into a situation where I have needed to do this. Basically, I have had an existing class library (for SharePoint development) and for some reason, I have decided I need to add ASP.NET file types to it (i.e. User Controls, Master Pages, etc.). A class library doesn't have these file types in the Add Item menu so you need a Web Application Project. When it comes down to it a Web Application Project really is the same thing as a class library, it just has some extra settings. So when it comes down to it, you would either have to recreate the project and add your existing files back into it or just hack the XML of your .csproj file. I obviously prefer the latter.
To do this, start by Unloading the Project by right clicking your project and choosing Unload Project. Next Right click on your unloaded project and choose Edit <PrjectName>.csproj. Paste the line below in the first ProjectGroup element. Usually Visual Studio puts it underneath the ProjectGuid element.
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
That is the only change that is required. There are some optional settings that you can put in regarding the configuration of Cassini, but none of them are required to get you going. You can always configure them in Visual Studio. Once you have made the change, save the .csproj file and Reload Project. Once the project is loaded, all of the ASP.NET file types will be present in your Add Item menu. When you compile, it will still compile everything down to a single DLL and you can deploy it just as if it was a regular class library.