How to convert Web application project to Class library project

前端 未结 4 1735
后悔当初
后悔当初 2020-12-24 05:54

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

Thanks

相关标签:
4条回答
  • 2020-12-24 06:35

    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)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
      • Remove <ProjectExtensions>
      • Under <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        • Change OutputPath to bin\Debug\
      • Under <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        • Change OutputPath to bin\Release\
    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
    0 讨论(0)
  • 2020-12-24 06:37

    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.

    0 讨论(0)
  • 2020-12-24 06:46

    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.

    0 讨论(0)
  • 2020-12-24 06:57

    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.

    0 讨论(0)
提交回复
热议问题