Thursday, June 18, 2009

Have you ever started out developing a class library for web parts or utility classes only to realize you later need to add a User Control or Page to the project? This can happen when working with SharePoint solutions as a popular way to develop and package solutions is as a class library project (DLL).

However, you can also package SharePoint solution DLLs by building a Web Application project file, which produces a single DLL which can then be deployed to the GAC or web application as part of a solution package (veterans of ASP.NET 1.x you will recognize web application projects as the way “it used to work” when developing web applications prior to ASP.NET 2.0). You just have to remember that it’s not a true web application project when deployed to SharePoint, because SharePoint “owns” the web application and if you add a Global.asax or Web.config to the project and then deploy as a solution, it won’t have any effect since SharePoint sees your code as a DLL (refer to this post for details of how to create an event handler in lieu of a Global.asax function). However, developing as a web application project in Visual Studio means you can work on User Controls and Pages which are then deployed in the solution as CONTROLTEMPLATES and LAYOUTS.

So if you have found yourself in the situation where you started out with a class library project and need to convert to a web application project, it’s an easy change to make. This change works even if your project has nothing to do with SharePoint.

Open the .csproj file in a text editor, and find the definition for ProjectGuid – it’s probably on or around line 7 (ignore the GUID below, that’s going to be specific to your .csproj file)

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{9A693F59-9C63-4424-A98D-D69A801C7614}</ProjectGuid>    

Paste this line after the <ProjectGuid> line:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Leave all other properties unchanged. Your file should now look something like this:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{9A693F59-9C63-4424-A98D-D69A801C7614}</ProjectGuid>    
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>        
    <OutputType>Library</OutputType>

Save the .csproj file and open in Visual Studio 2008. You should now be able to add Pages and User Controls to your project yet still compile to a single DLL suitable for deployment as part of a SharePoint solution.

Bookmark and Share  Comments [1] | Permalink | ASP.NET | SharePoint
Friday, August 14, 2009 4:01:43 AM (Mountain Daylight Time, UTC-06:00)
thankx mate you saved my life ;)
akuma

Leave a Comment

Name (required)
Email (will not be published)
Website
 

Comment Preview
Subscribe
Top 5 Posts
Add Google Analytics to a SharePoint Publishing Site
Integrating jQuery 1.3, ASP.NET 3.5 Visual Studio 2008
Add Custom Table Formats to SharePoint Content Editor
Configuring log4net for SharePoint Windows Authentication
Convert Visual Studio 2008 Class Library Project to Web Application Project
Tags
ASP.NET (5) dasBlog (5) GoogleAnalytics (2) jQuery (1) log4net (2) SharePoint (18) WebDesign (3)
 
 
 
Spreadfirefox Affiliate Button
 
Download Notepad++