如何将类库项目转换为Web应用程序项目?

发布于 2024-10-08 08:45:20 字数 203 浏览 8 评论 0原文

长话短说,由于架构方面的一些问题以及某人已经将一些 .aspx 文件放入类库中的事实,我想完成更改并将类库转换为 Web 应用程序。这是使用 Visual Studio 2010 和 .NET 4.0。有一个简单的方法可以做到这一点吗?谢谢!

编辑:我希望有一种比重新创建项目更好的方法,当我尝试创建一个新项目时,我遇到了太多引用损坏的问题,包括一个我似乎永远无法修复的问题。

Long story short, because of some issues with architecture and the fact that someone already put a few .aspx files in a class library, I'd like to just finish off the change and convert a class library to a web application. This is using Visual Studio 2010 and .NET 4.0. Is there an easy way of doing this? Thanks!

EDIT: I was hoping for a better method than recreating the project, I had too many issues with broken references when I tried just creating a new project, including one I could never seem to fix.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

瑾兮 2024-10-15 08:45:20

我今天在 Visual Studio 2005 中手动完成了此操作,因为它看起来比上面的更容易、更快。我刚刚将工作的 Web 应用程序 .csproj 文件与我的类库进行了比较,以确定相关差异。在此基础上,我做了以下修改。请记住,其他版本或您的个人项目可能会有所不同。

1) 在靠近顶部的 元素之后,我添加了

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

2) 我删除了 Local
3)在文件底部,就在关闭 之前,我添加了

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" />
      <ProjectExtensions>
        <VisualStudio>
          <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
            <WebProjectProperties>
              <UseIIS>False</UseIIS>
              <AutoAssignPort>True</AutoAssignPort>
              <DevelopmentServerPort>3291</DevelopmentServerPort>
              <DevelopmentServerVPath>/</DevelopmentServerVPath>
              <IISUrl>
              </IISUrl>
              <NTLMAuthentication>False</NTLMAuthentication>
            </WebProjectProperties>
          </FlavorProperties>
        </VisualStudio>
</ProjectExtensions>

I did this by hand today in Visual Studio 2005 because it seemed easier and faster than the above. I just diffed a working web application .csproj file with my class library to determine the relevant differences. Based on that, I made the following changes. Keep in mind that it may be different for other versions or your individual project.

1) Right after the <ProjectGuid> element near the top, I added

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

2) I removed <ProjectType>Local</ProjectType>
3) At the bottom of the file, right before the closing </Project>, I added

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" />
      <ProjectExtensions>
        <VisualStudio>
          <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
            <WebProjectProperties>
              <UseIIS>False</UseIIS>
              <AutoAssignPort>True</AutoAssignPort>
              <DevelopmentServerPort>3291</DevelopmentServerPort>
              <DevelopmentServerVPath>/</DevelopmentServerVPath>
              <IISUrl>
              </IISUrl>
              <NTLMAuthentication>False</NTLMAuthentication>
            </WebProjectProperties>
          </FlavorProperties>
        </VisualStudio>
</ProjectExtensions>
提笔落墨 2024-10-15 08:45:20

评论中已经提到了,但不知何故很容易错过(至少我错过了)。如果您应用了 Brad 的解决方案,但您的项目仍然缺少添加区域、控制器和视图的选项,则您仍然需要添加 MVC 项目 guid {E3E379DF-F4C6-4180-9B81-6769533ABE47}

ProjectTypeGuids 行现在应如下所示:

<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

正如 JamesQMurphy 所提到的,{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 在 VB 项目中不起作用。那是因为它是一个 C# 项目指南。因此,对于 VB 项目,必须使用 VB 项目 GUID。该指南是{F184B08F-C81C-45F6-A57F-5ABD9991F28F}

以下是一些已知项目 guid 的列表(取自 此站点):

  • ASP.NET MVC 1.0 {603C0E0B-DB56-11DC-BE95-000D561079B0}
  • ASP.NET MVC 2.0 {F85E285D-A4E0-4152-9332-AB1D724D3325}
  • ASP.NET MVC 3.0 {E53F8FEA-EAE0-44 A6- 8774-FFD645390401}
  • ASP.NET MVC 4.0 {E3E379DF-F4C6-4180-9B81-6769533ABE47
  • C# {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
  • C++ {8BC9CEB8-8B4A-11D0 -8D11-00A0C91BC942}
  • 数据库 {A9ACE9BB-CECE-4E62-9AA4-C7E7C5BD2124}
  • 数据库(其他项目类型){4F174C21-8C12-11D0-8340-0000F80270F8}
  • 部署 Cab {3EA9E505-35AC-4774-B492-AD1749C4943A}
  • 部署合并模块 {0 6A35CCD-C46D- 44D5-987B-CF40FF872267}
  • 部署设置 {978C614F-708E-4E1A-B201-565925725DBA}
  • 部署智能设备驾驶室 {AB322303-2255-48EF-A496-5904EB18DA55}
  • 分布式系统 {F135691A-BF7E-43 5D-8960-F99683D2D49C}
  • F# {F2A71F9B -5D33-465A-A702-920D77279786}
  • J# {E6FDF86B-F3D1-11D4-8576-0002A516ECE8}
  • 旧版 (2003) 智能设备 (C#) {20D4826A-C6FA-45DB-90F4-C717570B9F32}
  • 旧版 (200 3)智能设备(VB. NET) {CB4CE8C6-1BDB-4DC7-A4D3-65A1999772F8}
  • 模型-视图-控制器 v2 (MVC2) {F85E285D-A4E0-4152-9332-AB1D724D3325}
  • 模型-视图-控制器 v3 ( MVC3) {E53F8FEA-EAE0-44A6-8774-FFD645390401}
  • 模型-视图-控制器 v4 (MVC4) {E3E379DF-F4C6-4180-9B81-6769533ABE47}
  • Mono 适用于 Android {EFBA0AD7- 5A72-4C68-AF49-83D382785DCF}
  • MonoTouch {6BC8ED88-2882-458C-8E55-DFD12B67127B}
  • MonoTouch 绑定 {F5B4F3BC-B597-4E2B-B552-EF5D8A32436F}
  • 可移植类库 {786C830F-07A1- 408B-BD7F-6EE04809D6DB}
  • SharePoint(C# ) {593B0543-81F6-4436-BA1E-4747859CAAE2}
  • SharePoint (VB.NET) {EC05E597-79D4-47f3-ADA0-324C4F7C7484}
  • SharePoint 工作流程 {F8810EC1-6754-47FC-A15F-DFABD2E3FA90}
  • Silverlight {A15912 82-1198-4647- A2B1-27E5FF5F6F3B}
  • 智能设备 (C#) {4D628B5B-2FBC-4AA6-8C16-197242AEB884}
  • 智能设备 (VB.NET) {68B1623D-7FB9-47D8-8664-7ECEA3297D4F}
  • 解决方案文件夹 {2150E333-8FDC-42A3-94 74-1A3956D46DE8 }
  • 测试 {3AC096D0-A1C2-E12C-1390-A8335801FDAB}
  • VB.NET {F184B08F-C81C-45F6-A57F-5ABD9991F28F}
  • 可视化数据库工具 {C252FEB5-A946-4202-B1D4-9916A0590387 }
  • 视觉工作室应用程序工具 (VSTA) {A860303F-1F3F-4691-B57E-529FC101A107}
  • Visual Studio Office 工具 (VSTO) {BAA0C2D2-18E2-41B9-852F-F413020CAA33}
  • Web 应用程序 {349C5851-65DF-11DA-9384-00065B846 F21}
  • 网页网站{E24C65DC-7377-472B-9ABA-BC803B73C61A}
  • Windows(C#){FAE04EC0-301F-11D3-BF4B-00C04F794F79EFBC}
  • Windows (VB.NET)
  • (Visual C ++){ 8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}
  • Windows 通信基础 (WCF) {3D9AD99F-2412-4246-B90B-4EAA41C64699}
  • Windows Phone 8/8.1 空白/集线器/Webview 应用程序 {76F1466A-8B6D-4E39-A767-685A 06062A39}
  • 窗户Phone 8/8.1 应用程序 (C#) {C089C8C0-30E0-4E22-80C0-CE093F111A43}
  • Windows Phone 8/8.1 应用程序 (VB.NET) {DB03555F-0C8B-43BE-9FF9-57896B3C5E56}
  • Windows Presentation Foundation (WPF) {60DC8134- EBA5-43B8-BCC9-BB4BC16C2548}
  • Windows 应用商店 (Metro) 应用程序和应用程序组件 {BC8A1FFA-BEE3-4634-8014-F334798102B3}
  • 工作流程 (C#) {14822709-B5A1-4724-98CA-57A101D1B079}
  • 工作流程 (VB.NET) {D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8}
  • 工作流程基础 { 32F31D43-81CC -4C15-9DE6-3FC5453562B6}
  • Xamarin.Android {EFBA0AD7-5A72-4C68-AF49-83D382785DCF}
  • Xamarin.iOS {6BC8ED88-2882-458C-8E55-DFD12B67127B}
  • XNA (Windows) {6D335F3A-9D43-41b 4-9D22-F6F17C4BE596}
  • XNA (XBox) {2DF5C3F4-5A5F-47a9-8E94-23B4456F55E2}
  • XNA (Zune) {D399B71A-8929-442a-A9AC-8BEC78BB2433}

PS 如果您想知道,该列表显然是公共领域。

It's mentioned in the comments already, but somehow it's easy to miss (at least I missed it). If you applied Brad's solution, but your project is still missing the option to add areas, controllers and views, you still need to add an MVC project guid {E3E379DF-F4C6-4180-9B81-6769533ABE47}.

The ProjectTypeGuids line should now look like this:

<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

As mentioned by JamesQMurphy, {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} will not work in VB projects. That's because it's a C# project guid. So for VB project a VB project guid has to be used. This guid is {F184B08F-C81C-45F6-A57F-5ABD9991F28F}.

Here is a list of some of the known project guids (taken from this site):

  • ASP.NET MVC 1.0 {603C0E0B-DB56-11DC-BE95-000D561079B0}
  • ASP.NET MVC 2.0 {F85E285D-A4E0-4152-9332-AB1D724D3325}
  • ASP.NET MVC 3.0 {E53F8FEA-EAE0-44A6-8774-FFD645390401}
  • ASP.NET MVC 4.0 {E3E379DF-F4C6-4180-9B81-6769533ABE47
  • C# {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
  • C++ {8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}
  • Database {A9ACE9BB-CECE-4E62-9AA4-C7E7C5BD2124}
  • Database (other project types) {4F174C21-8C12-11D0-8340-0000F80270F8}
  • Deployment Cab {3EA9E505-35AC-4774-B492-AD1749C4943A}
  • Deployment Merge Module {06A35CCD-C46D-44D5-987B-CF40FF872267}
  • Deployment Setup {978C614F-708E-4E1A-B201-565925725DBA}
  • Deployment Smart Device Cab {AB322303-2255-48EF-A496-5904EB18DA55}
  • Distributed System {F135691A-BF7E-435D-8960-F99683D2D49C}
  • F# {F2A71F9B-5D33-465A-A702-920D77279786}
  • J# {E6FDF86B-F3D1-11D4-8576-0002A516ECE8}
  • Legacy (2003) Smart Device (C#) {20D4826A-C6FA-45DB-90F4-C717570B9F32}
  • Legacy (2003) Smart Device (VB.NET) {CB4CE8C6-1BDB-4DC7-A4D3-65A1999772F8}
  • Model-View-Controller v2 (MVC2) {F85E285D-A4E0-4152-9332-AB1D724D3325}
  • Model-View-Controller v3 (MVC3) {E53F8FEA-EAE0-44A6-8774-FFD645390401}
  • Model-View-Controller v4 (MVC4) {E3E379DF-F4C6-4180-9B81-6769533ABE47}
  • Mono for Android {EFBA0AD7-5A72-4C68-AF49-83D382785DCF}
  • MonoTouch {6BC8ED88-2882-458C-8E55-DFD12B67127B}
  • MonoTouch Binding {F5B4F3BC-B597-4E2B-B552-EF5D8A32436F}
  • Portable Class Library {786C830F-07A1-408B-BD7F-6EE04809D6DB}
  • SharePoint (C#) {593B0543-81F6-4436-BA1E-4747859CAAE2}
  • SharePoint (VB.NET) {EC05E597-79D4-47f3-ADA0-324C4F7C7484}
  • SharePoint Workflow {F8810EC1-6754-47FC-A15F-DFABD2E3FA90}
  • Silverlight {A1591282-1198-4647-A2B1-27E5FF5F6F3B}
  • Smart Device (C#) {4D628B5B-2FBC-4AA6-8C16-197242AEB884}
  • Smart Device (VB.NET) {68B1623D-7FB9-47D8-8664-7ECEA3297D4F}
  • Solution Folder {2150E333-8FDC-42A3-9474-1A3956D46DE8}
  • Test {3AC096D0-A1C2-E12C-1390-A8335801FDAB}
  • VB.NET {F184B08F-C81C-45F6-A57F-5ABD9991F28F}
  • Visual Database Tools {C252FEB5-A946-4202-B1D4-9916A0590387}
  • Visual Studio Tools for Applications (VSTA) {A860303F-1F3F-4691-B57E-529FC101A107}
  • Visual Studio Tools for Office (VSTO) {BAA0C2D2-18E2-41B9-852F-F413020CAA33}
  • Web Application {349C5851-65DF-11DA-9384-00065B846F21}
  • Web Site {E24C65DC-7377-472B-9ABA-BC803B73C61A}
  • Windows (C#) {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
  • Windows (VB.NET) {F184B08F-C81C-45F6-A57F-5ABD9991F28F}
  • Windows (Visual C++) {8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}
  • Windows Communication Foundation (WCF) {3D9AD99F-2412-4246-B90B-4EAA41C64699}
  • Windows Phone 8/8.1 Blank/Hub/Webview App {76F1466A-8B6D-4E39-A767-685A06062A39}
  • Windows Phone 8/8.1 App (C#) {C089C8C0-30E0-4E22-80C0-CE093F111A43}
  • Windows Phone 8/8.1 App (VB.NET) {DB03555F-0C8B-43BE-9FF9-57896B3C5E56}
  • Windows Presentation Foundation (WPF) {60DC8134-EBA5-43B8-BCC9-BB4BC16C2548}
  • Windows Store (Metro) Apps & Components {BC8A1FFA-BEE3-4634-8014-F334798102B3}
  • Workflow (C#) {14822709-B5A1-4724-98CA-57A101D1B079}
  • Workflow (VB.NET) {D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8}
  • Workflow Foundation {32F31D43-81CC-4C15-9DE6-3FC5453562B6}
  • Xamarin.Android {EFBA0AD7-5A72-4C68-AF49-83D382785DCF}
  • Xamarin.iOS {6BC8ED88-2882-458C-8E55-DFD12B67127B}
  • XNA (Windows) {6D335F3A-9D43-41b4-9D22-F6F17C4BE596}
  • XNA (XBox) {2DF5C3F4-5A5F-47a9-8E94-23B4456F55E2}
  • XNA (Zune) {D399B71A-8929-442a-A9AC-8BEC78BB2433}

P.S. In case you wonder, the list is apparently public domain.

屋檐 2024-10-15 08:45:20

在解决方案中创建一个新的 Web 应用程序项目,并将所有文件从类库拖放到新的 Web 应用程序项目中。

Create a new web application project in your solution and drag and drop all files from class library to the new web application project.

何以笙箫默 2024-10-15 08:45:20

在.net core 3.1中修改项目文件[项目名称].csproj并更改

<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk.Web">

现在保存更改并重新加载项目,现在您有一个Web应用程序(MVC)项目。

in .net core 3.1 modify the project file [project name].csproj and change

<Project Sdk="Microsoft.NET.Sdk">

to

<Project Sdk="Microsoft.NET.Sdk.Web">

now save changes and reload the project, now you have a web app (MVC) project.

遥远的绿洲 2024-10-15 08:45:20

创建一个新的 Web 项目,然后将类文件和 *.aspx 文件复制到新的 Web 项目中是不是最简单?

Would it be easiest to just create a new web project, then copy over the class files and *.aspx files into the new web project?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文