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.

Comments

# Links (2/24/2008) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

Sunday, February 24, 2008 7:06 PM by Links (2/24/2008) « Steve Pietrek’s SharePoint Stuff

Pingback from  Links (2/24/2008) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

# re: How to: Hack a Class Library Project into a Web Application Project

Thursday, February 4, 2010 8:55 AM by Umit

I have tried this and it works. the problem is when I try to use webcontrol which is created the classlibrary anything does display on page. do you have any idea?

here is my sample code:

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<%@ Register Assembly="ClassLibrary1" Namespace="ClassLibrary1" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/.../xhtml1-transitional.dtd">

<html xmlns="www.w3.org/.../xhtml" >

<head runat="server">

   <title></title>

</head>

<body>

   <form id="form1" runat="server">

   <div>

   <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />

   <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>

   </div>

   </form>

</body>

</html>

protected override void OnLoad(EventArgs e)

       {

           base.OnLoad(e);

           ph.Controls.Add(Page.LoadControl(typeof(ClassLibrary1.WebUserControl1), null));

       }

# re: How to: Hack a Class Library Project into a Web Application Project

Friday, April 16, 2010 1:54 PM by Ali Khan

This really helped me for the type of solution I needed and how I am developing for SharePoint.

Thank you very much for posting this.

# Visual Studio Project GUIDS | Zabriskie Answers

Saturday, December 13, 2014 5:06 PM by Visual Studio Project GUIDS | Zabriskie Answers

Pingback from  Visual Studio Project GUIDS | Zabriskie Answers

# re: How to: Hack a Class Library Project into a Web Application Project

Wednesday, September 7, 2016 7:18 AM by Andrew

That is exactly what I was looking for... Thanks a lot!

Leave a Comment

(required) 
(required) 
(optional)
(required)