asp.net-mvc 如何在 Visual Studio 2012 或 Visual Studio 2013 中打开旧的 MVC 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13424079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I open an old MVC project in Visual Studio 2012 or Visual Studio 2013?
提问by ahsteele
I have an old ASP.NET MVC 2 project which I do not want to upgrade to MVC 3 or MVC 4. I am working on a new machine running Windows 8, Visual Studio 2012 and Visual Studio 2013. When I try to open the MVC 2 project in VS 2012 or VS 2013 I receive the error:
我有一个旧的 ASP.NET MVC 2 项目,我不想升级到 MVC 3 或 MVC 4。我正在一台运行 Windows 8、Visual Studio 2012 和 Visual Studio 2013 的新机器上工作。当我尝试打开 MVC 时VS 2012 或 VS 2013 中的 2 个项目我收到错误:
This project is incompatible with the current edition of Visual Studio
此项目与当前版本的 Visual Studio 不兼容
The project is then unloaded and grayed out in Solution Explorer. I do not want to install another copy of Visual Studio. How can I open an old MVC project in a new version of Visual Studio?
然后该项目在解决方案资源管理器中卸载并变灰。我不想安装 Visual Studio 的另一个副本。如何在新版本的 Visual Studio 中打开旧的 MVC 项目?
回答by ahsteele
Opening an unsupported MVC project in Visual Studio 2012or Visual Studio 2013 is actually pretty easy to accomplish with two steps. In fact, as bytebender's comment indicates, these same steps shouldapply to and work for MVC 1 projects. However, I haven't tested them and therefore cannot guarantee that they do in fact work.
在Visual Studio 2012或 Visual Studio 2013 中打开不受支持的 MVC 项目实际上很容易通过两个步骤完成。事实上,正如bytebender 的评论所指出的,这些相同的步骤应该适用于 MVC 1 项目并适用于 MVC 1 项目。但是,我没有测试过它们,因此不能保证它们确实有效。
Assuming that you have not already done so step one is to download and install MVC 1, MVC 2or MVC 3(close Visual Studio before starting the installation).
假设您还没有这样做,那么第一步是下载并安装MVC 1、MVC 2或MVC 3(在开始安装之前关闭 Visual Studio)。
Once you have the appropriate flavor of MVC installed the project will still not load in VS 2012. This is because ASP.NET MVC projects are a project subtypeof the Web Application project type. This means that the project has additional add ins and features available to it when used within Visual Studio.
一旦您安装了适当的 MVC 风格,该项目仍然不会在 VS 2012 中加载。这是因为 ASP.NET MVC 项目是Web 应用程序项目类型的项目子类型。这意味着在 Visual Studio 中使用时,项目具有可用的附加加载项和功能。
Both Visual Studio 2012 and Visual Studio 2013 are limited in their backwards compatibility with ASP.NET MVC and other project types. Unfortunately, installing the old MVC bits did not change that. Visual Studio 2012 is compatiblewith the ASP.NET MVC 3 and 4 project flavors. Visual Studio 2013 is compatiblewith MVC 4 and MVC 5.
Visual Studio 2012 和 Visual Studio 2013 与 ASP.NET MVC 和其他项目类型的向后兼容性都受到限制。不幸的是,安装旧的 MVC 位并没有改变这一点。Visual Studio 2012与 ASP.NET MVC 3 和 4 项目风格兼容。Visual Studio 2013与 MVC 4 和 MVC 5兼容。
To get the project to load you will have to modify the project file. To do so right click on the unloaded project and select Edit. Which will open the project file as an XML text file. Find the ProjectTypeGuidsnode which should look something like this:
要加载项目,您必须修改项目文件。为此,右键单击卸载的项目并选择编辑。这会将项目文件作为 XML 文本文件打开。找到ProjectTypeGuids应该看起来像这样的节点:
<ProjectTypeGuids>
{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Remove the appropriate Project Guid from the list:
从列表中删除相应的项目指南:
- ASP.NET MVC 1:
{603c0e0b-db56-11dc-be95-000d561079b0} - ASP.NET MVC 2:
{F85E285D-A4E0-4152-9332-AB1D724D3325}(shown in example above) - ASP.NET MVC 3:
{E53F8FEA-EAE0-44A6-8774-FFD645390401} - ASP.NET MVC 4:
{E3E379DF-F4C6-4180-9B81-6769533ABE47}
- ASP.NET MVC 1:
{603c0e0b-db56-11dc-be95-000d561079b0} - ASP.NET MVC 2:(
{F85E285D-A4E0-4152-9332-AB1D724D3325}如上例所示) - ASP.NET MVC 3:
{E53F8FEA-EAE0-44A6-8774-FFD645390401} - ASP.NET MVC 4:
{E3E379DF-F4C6-4180-9B81-6769533ABE47}
With the appropriate GUID removed the ProjectTypeGuidsshould look similar to this:
删除适当的 GUID 后,它ProjectTypeGuids应该类似于:
<ProjectTypeGuids>
{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Save the file and close the Visual Studio project file editor. Right click the project and select reload. If the project does not reload close and reopen Visual Studio. You should now be able to work with your old ASP.NET MVC project in your new version of Visual Studio.
保存文件并关闭 Visual Studio 项目文件编辑器。右键单击项目并选择重新加载。如果项目没有重新加载,请关闭并重新打开 Visual Studio。您现在应该可以在新版本的 Visual Studio 中使用旧的 ASP.NET MVC 项目。
One important thing to note is that after these modifications Visual Studio is not aware that this is an ASP.NET MVC project; therefore the project-specific features like "Add Controller, View etc." will not be present in menus.
需要注意的一件重要事情是,经过这些修改后,Visual Studio 不知道这是一个 ASP.NET MVC 项目;因此,项目特定的功能,如“添加控制器、视图等”。不会出现在菜单中。
回答by Ruben Bartelink
I used @ahsteele's approach (thanks and 2x+1s!), but was having one further error:-
我使用了@ahsteele 的方法(感谢和 2x+1s!),但又出现了一个错误:-
.csproj : error : The operation could not be completed. Invalid class string
.csproj:错误:操作无法完成。无效的类字符串
I can't find any citations for the real cause of that, but I was able to get VS2012RTM to load the project successfully by changing the <ProjectGuid>. (No idea how this happened - its part of a large solution and VS08, VS10, VS11 Beta and VS2012RC have all upgraded the .csprojand .slnover time.
我找不到真正原因的任何引文,但我能够通过更改<ProjectGuid>. (不知道这是怎么发生-一个大的解决方案,它的一部分VS08,VS10,VS11 Beta版和VS2012RC都升级.csproj并.sln随着时间的推移。
回答by WickStargazer
In VS2017 the solution is to just make it like <ProjectTypeGuids></ProjectTypeGuids>so.
在 VS2017 中,解决方案就是让它像<ProjectTypeGuids></ProjectTypeGuids>这样。
No Spaces in between ladies and gentlemen, otherwise it will waste 48 hours of your time.
女士们先生们之间没有空格,否则会浪费您48小时的时间。
Regards
问候

