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.