升级到 MVC 5 和 Web API 2 后,如何让我的 Web API 应用程序再次运行? [英] How can I get my Web API app to run again after upgrading to MVC 5 and Web API 2?

查看:19
本文介绍了升级到 MVC 5 和 Web API 2 后,如何让我的 Web API 应用程序再次运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此指南将我的 Web API 应用升级到 funkelnagelneu 版本:

http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

但是,在完成这些步骤之后(无论如何,这一切似乎都应该是自动化的),我尝试运行它并得到,无法直接启动输出类型为类库的项目"

Sam Hills Brothers Coffee 在这里发生了什么?谁说这是班级图书馆?

所以我打开了项目">属性",并将它(由于某种原因它标记为类库"——要么不是昨天,要么工作正常)到输出类型Windows 应用程序"(控制台应用程序"和类库"是唯一的其他选项).

现在它不会编译,抱怨:程序 'c:Platypus_Server_WebAPIPlatypusServerWebAPIPlatypusServerWebAPIobjDebugPlatypusServerWebAPI.exe' 不包含适合入口点的静态 'Main' 方法..."

鉴于此困境,我如何才能让我的 Web API 应用程序备份并运行?

更新

查看packages.config,有两个条目似乎值得一看:

<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40"/>

其他所有目标都针对 net451.这可能是问题吗?我应该删除这些包吗?

更新 2

我试图通过 NuGet 包管理器卸载 Microsoft.Web.Infrastructure 包(它的描述让我相信我不需要它;而且,它没有依赖项),但它告诉我,NuGet 无法在以下项目中安装或卸载选定的包.[mine]"

更新 3

我又一步步进去了,发现自己漏了一步.我不得不在应用程序 web.config 文件中更改此条目:

<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/><bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0"/></dependentAssembly>

(从4.0.0.0"到5.0.0.0")

...但我仍然得到相同的结果 - 它重建/编译,但不会运行,无法直接启动输出类型为类库的项目">

更新 4

考虑到 err msg,它不能直接打开类库,我想,当然你不能/不会——这是一个网络应用程序,而不是一个项目.所以我遵循了一种预感,关闭项目,然后将其作为网站重新打开(而不是重新打开项目).

这至少让我走得更远;现在我看到了一个 YSOD:

无法加载文件或程序集System.Web.WebPages.Razor,版本=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"或其依赖项之一.系统找不到指定的文件.

更新 5

注意:该项目现在(作为网站打开后)名为localhost_48614"

而且……不再有参考"文件夹……?!?!?

至于我得到的 YSOD,官方说明 (http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2) 说要这样做,我引用:

"将包含System.Web.WebPages.Razor"的所有元素从2.0.0.0"版本更新为
版本3.0.0.0"
."

更新 6

当我现在选择工具">库包管理器">管理解决方案的 NuGet 包"时,出现操作失败.无法找到解决方案目录.请确保已保存解决方案."

所以我保存它,它用这个时髦的新名称保存它 (C:UsersclayDocumentsVisual Studio 2013Projectslocalhost_48614localhost_48614.sln)

我在 NuGet 包管理器的顶部看到了黄色的启蒙带我,此解决方案中缺少某些 NuGet 包.单击以从您的在线恢复包源."

我这样做了(即单击恢复"按钮),它会下载丢失的包……我最终得到了 30 个包.

我尝试再次运行应用程序/站点,然后……以前的 YSOD 变成了编译错误:

预应用程序启动初始化方法 Start on type System.Web.Mvc.PreApplicationStartCode 引发异常并显示以下错误消息:无法加载文件或程序集System.Web.WebPages.Razor,版本 = 3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一.系统找不到指定的文件..

啊啊啊啊!!!(这甚至不是像海盗一样说话的日子).

更新 7

我仍然很好奇为什么 Humpty Dumpty 摔倒并打破了他的王冠(可以这么说),但我最终认输并创建了一个新项目,复制和粘贴代码 - 并且它工作正常(VS2013 和 Web API,具有从 VS 2008、.NET 3.5 客户端应用程序调用的 REST 方法).

解决方案

在迁移指南的最后一步中,您是否删除了指定的 MVC4 项目 Guid?我和你有同样的问题,当我回溯我的步骤时,我意识到我已经删除了我的 .csproj 文件中的所有三个 Guid.我恢复了此元素中的其他 Guid,解决方案现在将其识别为 MVC 应用程序,现在工作正常.所以这一行现在是:

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

希望有帮助

I upgraded my Web API app to the funkelnagelneu versions using this guidance:

http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

However, after going through the steps (it seems all this should be automated, anyway), I tried to run it and got, "A project with an Output Type of Class Library cannot be started directly"

What in Sam Hills Brothers Coffee is going on here? Who said this was a class library?

So I opened Project > Properties, and changed it (it was marked as "Class Library" for some reason - it either wasn't yesterday, or was and worked fine) to an Output Type of "Windows Application" ("Console Application" and "Class Library" being the only other options).

Now it won't compile, complaining: "Program 'c:Platypus_Server_WebAPIPlatypusServerWebAPIPlatypusServerWebAPIobjDebugPlatypusServerWebAPI.exe' does not contain a static 'Main' method suitable for an entry point..."

How can I get my Web API app back up and running in view of this quandary?

UPDATE

Looking in packages.config, two entries seem chin-scratch-worthy:

<package id="Microsoft.AspNet.Providers" version="1.2" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />

All the others target net451. Could this be the problem? Should I remove these packages?

UPDATE 2

I tried to uninstall the Microsoft.Web.Infrastructure package (its description leads me to believe I don't need it; also, it has no dependencies) via the NuGet package manager, but it tells me, "NuGet failed to install or uninstall the selected package in the following project(s). [mine]"

UPDATE 3

I went through the steps in again, and found that I had missed one step. I had to change this entry in the Application web.config File :

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

(from "4.0.0.0" to "5.0.0.0")

...but I still get the same result - it rebuilds/compiles, but won't run, with "A project with an Output Type of Class Library cannot be started directly"

UPDATE 4

Thinking about the err msg, that it can't directly open a class library, I thought, "Sure you can't/won't -- this is a web app, not a project. So I followed a hunch, closed the project, and reopened it as a website (instead of reopening a project).

That has gotten me further, at least; now I see a YSOD:

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

UPDATE 5

Note: The project is now (after being opened as a web site) named "localhost_48614"

And...there is no longer a "References" folder...?!?!?

As to that YSOD I'm getting, the official instructions (http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2) said to do this, and I quote:

"Update all elements that contain "System.Web.WebPages.Razor" from version "2.0.0.0" to
version"3.0.0.0"
."

UPDATE 6

When I select Tools > Library Package Manager > Manage NuGet Packages for Solution now, I get, "Operation failed. Unable to locate the solution directory. Please ensure that the solution has been saved."

So I save it, and it saves it with this funky new name (C:UsersclayDocumentsVisual Studio 2013Projectslocalhost_48614localhost_48614.sln)

I get the Yellow Strip of Enlightenment across the top of the NuGet Package Manager telling me, "Some NuGet packages are missing from this solution. Click to restore from your online package sources."

I do (click the "Restore" button, that is), and it downloads the missing packages ... I end up with the 30 packages.

I try to run the app/site again, and ... the erstwhile YSOD becomes a compilation error:

The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

Argghhhh!!! (and it's not even talk-like-a-pirate day).

UPDATE 7

I'm still curious about why Humpty Dumpty fell down and broke his crown (so to speak), but I finally threw in the towel and created a new project, copying-and-pasting code - and it works fine (VS 2013 and Web API, with REST methods called from a VS 2008, .NET 3.5 client app).

解决方案

In the last step on the migration guide did you delete only the MVC4 Project Guid that is specified? I had the same problem as you and when I retraced my steps realised that I had deleted all three of the Guids within in my .csproj file. I restored the other Guids within this element and the solution now recognises it as a MVC application and now works OK. So the line now reads:

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

Hope that helps

这篇关于升级到 MVC 5 和 Web API 2 后,如何让我的 Web API 应用程序再次运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆