in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

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

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) « Steve Pietrek’s SharePoint Stuff said:

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

February 24, 2008 7:06 PM
 

Umit said:

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));

       }

February 4, 2010 8:55 AM
 

Ali Khan said:

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.

April 16, 2010 1:54 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems