How to convert Web application project to Class library project

I need to convert a project started as a Web Application to a Class Libray, is this possible?

Thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The correct answer is yes. Just edit the csproj (msbuild) file and change the ProjectGuid and remove the ProjectTypeGuids:

<ProjectGuid>{9845066A-3C9E-4F51-8F5F-8F513E8D03C1}</ProjectGuid>

It really is that simple.

Method 2

If you want to make it exactly the same as a class library project, here’s how to do it for a Visual Studio 2010 project:

  1. Edit the csproj file
    • Under PropertyGroup
      • Remove ProjectTypeGuids
      • Remove UseIISExpress
      • Add <FileAlignment>512</FileAlignment>
    • Change <Import Project="$(MSBuildBinPath)Microsoft.CSharp.targets" /> to <Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
    • Remove <Import Project="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov10.0WebApplicationsMicrosoft.WebApplication.targets" />
    • Remove <ProjectExtensions>
    • Under <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
      • Change OutputPath to binDebug
    • Under <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
      • Change OutputPath to binRelease
  2. Open the project in Visual Studio
    • Remove any of the following references if they are unused
      • System.Configuration
      • System.Drawing
      • System.EnterpriseServices
      • System.Web
      • System.Web.ApplicationServices
      • System.Web.DynamicData
      • System.Web.Entity
      • System.Web.Extensions
      • System.Web.Services
    • Delete any of the following files/folders if they are unwanted/unused
      • App_Data
      • *.aspx
      • Web.config
      • Scripts
      • Styles
      • Global.asax
      • Site.Master

Method 3

No. Your best bet is to create a Class.Library and copy the .cs files into your new project.

A Class Library won’t do anything with .aspx pages, it will see those as files in the solution.

Method 4

I came here to have a class library with mvc menu items. This is, right click on views folder to add view or controller to add controller within a classlibrary.

I was able to achieve this by editing my mvc.web.app.csproj, copy the <ProjectTypeGuids /> to my class.lib.csproj project.

For more context on what I am doing, see: How to reuse Areas, Controllers, Views, Models, Routes in multiple apps or websites.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x