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

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

问题描述

我升级我的Web API应用程序来使用这个指导funkelnagelneu版本:

<一个href=\"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\">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

然而,通过步骤后(似乎这一切应该是自动的,反正),我试图运行它,并得到了与一个类库输出类型的项目不能直接启动

在山姆山兄弟咖啡到底是怎么回事?谁说,这是一个类库?

所以,我打开项目>属性,并改变它(它的的标记为类库出于某种原因 - 它要么是不是昨天,还是和精细的工作)到一个输出类型Windows应用程序(控制台应用程序和类库是唯一的其他选择)。

现在它不会编译,抱怨:*计划'c:\\Platypus_Server_WebAPI\\PlatypusServerWebAPI\\PlatypusServerWebAPI\\obj\\Debug\\PlatypusServerWebAPI.exe'不包含适合的切入点?*?

静态主的方法我

如何才能让我的Web应用程序的API备份和运行鉴于这种窘境?

更新

展望packages.config,两个条目似乎下巴划伤值得:

 &LT;包ID =Microsoft.AspNet.Providers版本=1.2targetFramework =net40/&GT;
&LT;包ID =Microsoft.Web.Infrastructure版本=1.0.0.0targetFramework =net40/&GT;

所有的人目标net451。难道这是问题吗?我是否应该删除这些软件包?

更新2

我试图卸载Microsoft.Web.Infrastructure包(其描述使我相信我不需要它;另外,它没有依赖关系)通过的NuGet包管理器,但它告诉我,的NuGet安装失败或在以下项目(S)卸载选定的包。[矿]

更新3

我通过中的步骤再次去了,发现我错过了一步。我不得不改变在应用程序的web.config文件此项:

 &LT; dependentAssembly&GT;
    &LT; assemblyIdentity名称=System.Web.Mvc公钥=31bf3856ad364e35/&GT;
    &LT; bindingRedirect oldVersion =1.0.0.0-5.0.0.0NEWVERSION =5.0.0.0/&GT;
&LT; / dependentAssembly&GT;

(从4.0.0.0改为5.0.0.0)

...但我仍然得到同样的结果 - 它重建/编译,但不会跑,用的与一个类库输出类型的项目不能直接启动

更新4

思考的错误消息,它不能直接打开一个类库,我想,你当然不能/不会 - 这是一个web应用程序,而不是一个项目,所以我也跟着直觉,关闭项目,并重新打开它作为一个网站(而不是重新打开一个项目)。

这也进一步得到了我,至少,现在我看到一个YSOD:

无法加载文件或程序集System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31bf3856ad364e35或它的一个依赖。该系统找不到指定的文件。

更新5

请注意:该项目是目前命名为localhost_48614

(被打开一个网站后)

和......不再有一个参考的文件夹...?!?!?

至于说YSOD我得到的官方说明(<一个href=\"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\">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)说到做到这一点,我引述如下:

更新包含的所有元素,从版本2.0.0.0,以结果System.Web.WebPages.Razor
版本3.0.0.0
的。

更新6

当我选择工具>库软件包管理器>管理的NuGet的解决方案包,现在,我收到操作失败,无法找到解决方案目录,请确保该解决方案已被保存。

所以我保存它,并将它与这个时髦​​的新名称保存(C:\\用户\\粘土\\文档\\的Visual Studio 2013 \\项目\\ localhost_48614 \\ localhost_48614.sln)

我得到启蒙的黄色地带跨越的NuGet包管理器的告诉顶部
我的部分的NuGet包从溶液中失踪。单击可从您的在线恢复
包的来源。

我(点击恢复按钮,即是),并下载缺少的包......我结束了30包。

我尝试再次运行应用程序/网站,并...昔日YSOD成为一个编译错误:

的上型System.Web.Mvc preApplicationStart code pre-应用程序启动初始化方法开始抛出一个异常,出现以下错误信息:无法加载文件或程序系统.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31bf3856ad364e35或它的一个依赖。该系统找不到指定的文件。

Argghhhh !!! (和它甚至没有说话样一个海盗天)。

更新7

我还是很好奇,为什么矮胖掉了下来,并打破了他的王冠(这么说),但我终于在认输,并创建了一个新的项目,复制和粘贴code - 和它的作品精(VS 2013和Web的API,从2008年VS REST叫方法,.NET 3.5客户端应用程序)。


解决方案

在对迁移指南的最后一步你删除的的MVC4项目的Guid被指定?我有同样的问题,因为你,当我原路意识到,我已经在我的.csproj文件中删除所有三个GUID的范围内。我恢复了其他的GUID这个元素内和解决方案现在将其识别为一个MVC应用程序,现在工程确定。因此,该行现在读取:

<$p$p><$c$c><ProjectTypeGuids>{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_WebAPI\PlatypusServerWebAPI\PlatypusServerWebAPI\obj\Debug\PlatypusServerWebAPI.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:\Users\clay\Documents\Visual Studio 2013\Projects\localhost_48614\localhost_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

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

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