Visual Studio - Converting a library project to web application project (WAP)

So it happened that I had a library project in a large solution in Visual Studio 2010 that I now wanted to operate as a Web Application project so I can configure an IIS application for it (it was bascially a bridge project for communication with a third-party library to which I now needed to add HttpHandlers to provide http end-points for interaction with the third-party library).

I initially did not had any idea on how to do this and I decided to go with the "diff" way. Basically I "diffed" the project file for this library project with a regular WAP project in the solution. Apart from the obvious differences for references, project files etc., one important difference between the two project files was the presence of an extra <ProjectTypeGuids> element in the WAP project file which looked something like the following:

 

{syntaxhighlighter brush: xml;fontsize: 100; first-line: 1; }<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> {/syntaxhighlighter}

Then I diffed the library project file with another WAP project from the same solution, the result came out to be the same, the presence of <ProjectTypeGuids> element was the only noticeable difference. Finally I diffed the 2 WAP project files and they did not vary much apart from the usual suspects of references, project files and build events section. But importantly, both of those WAP projects had the same <ProjectTypeGuids> element.

A bit encouraged with this analysis, I unloaded the library project in Visual Studio and opened its project file for editing (right-click the project in Solution Explorer after unloading it and select "Edit project name" from the menu).

Then I went-ahead and added the above <ProjectTypeGuids> element below the <ProjectGuid> element (which was the child of the first <PropertyGroup> element in the project file). So now my project file looked like the following:

 

{syntaxhighlighter brush: xml;fontsize: 100; first-line: 1; }<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{C8ACCFB0-FB4C-45D6-A525-1119F61D4398}</ProjectGuid> <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>Something</RootNamespace> <AssemblyName>MyAssembly</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <FileUpgradeFlags> </FileUpgradeFlags> <OldToolsVersion>4.0</OldToolsVersion> <UpgradeBackupLocation /> <!-- More content -->{/syntaxhighlighter}

Notice the <ProjectTypeGuids> element just below the <ProjectGuid> element.

I saved the file and when I reloaded the project in Visual Studio, voila, it recognined the change. VS automatically created the web.config file in the project root folder also (that was the only noticeable difference Visual Studio made after I reloaded the project).

When I tried building the project, it built fine, but I noticed that the build output was going to Bin\Debug and Bin\Release sub-folders under project folder (instead of the usual Bin folder for a WAP project). I unloaded the project another time, opened project file for editing again, searched for <OutputPath> elements everywhere and updated them to contain "Bin\" value (I later realized I could have done it from Project's property pages too).

So, in a nut-shell, if you want to convert a regular library project to a WAP project, here is what you should do:

  1. Unload the project in Visual Studio and open the project file for editing.
  2. Insert this below the <ProjectGuid> element:

    {syntaxhighlighter brush: xml;fontsize: 100; first-line: 1; }<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>{/syntaxhighlighter} 

  3. Save the project file and close it.
  4. Re-load the project in Visual Studio.
  5. Open project property pages and adjust build paths (optional). 
  6. Adjust web.config settings (optional).