如何将类库项目转换为Web应用程序项目?
长话短说,由于架构方面的一些问题以及某人已经将一些 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我今天在 Visual Studio 2005 中手动完成了此操作,因为它看起来比上面的更容易、更快。我刚刚将工作的 Web 应用程序 .csproj 文件与我的类库进行了比较,以确定相关差异。在此基础上,我做了以下修改。请记住,其他版本或您的个人项目可能会有所不同。
1) 在靠近顶部的
元素之后,我添加了2) 我删除了Local
3)在文件底部,就在关闭
之前,我添加了
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 added2) I removed
<ProjectType>Local</ProjectType>
3) At the bottom of the file, right before the closing
</Project>
, I added评论中已经提到了,但不知何故很容易错过(至少我错过了)。如果您应用了 Brad 的解决方案,但您的项目仍然缺少添加区域、控制器和视图的选项,则您仍然需要添加 MVC 项目 guid
{E3E379DF-F4C6-4180-9B81-6769533ABE47}
。ProjectTypeGuids
行现在应如下所示:正如 JamesQMurphy 所提到的,
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
在 VB 项目中不起作用。那是因为它是一个 C# 项目指南。因此,对于 VB 项目,必须使用 VB 项目 GUID。该指南是{F184B08F-C81C-45F6-A57F-5ABD9991F28F}
。以下是一些已知项目 guid 的列表(取自 此站点):
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: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):
P.S. In case you wonder, the list is apparently public domain.
在解决方案中创建一个新的 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.
在.net core 3.1中修改项目文件[项目名称].csproj并更改
为
现在保存更改并重新加载项目,现在您有一个Web应用程序(MVC)项目。
in .net core 3.1 modify the project file [project name].csproj and change
to
now save changes and reload the project, now you have a web app (MVC) project.
创建一个新的 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?