问题描述
我最近开始关注 本指南 将我的项目迁移到 .NET 4.5.1 和 Web Api 2.
I recently started following this guide to migrate my project to .NET 4.5.1 and Web Api 2.
MS 开发人员 Rick Anderson 要求您做的第一件事就是改变:
The very first thing MS developer Rick Anderson asks you to do is change:
WebApiConfig.Register(GlobalConfiguration.Configuration);
到
GlobalConfiguration.Configure(WebApiConfig.Register);
在 global.asax 文件中.然而,当我尝试构建时,这给了我一个错误:
in the global.asax file. Yet this is giving me an error when I try to build:
错误 1 'System.Web.Http.GlobalConfiguration' 不包含 'Configure' 的定义
我的项目目前基于 MVC 5 和 Web Api 2 以及 .NET 4.5.1,但我认为 System.Web.Http 仍然认为它是 .NET 4.0 版本.
My project is currently on MVC 5 and Web Api 2 and .NET 4.5.1, yet I think System.Web.Http still thinks it's the .NEt 4.0 version.
我该如何解决这个问题?
How can I go about fixing this?
谢谢.
这是我的程序集绑定:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
<!--
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly> -->
</assemblyBinding>
在顶部被评论后的所有内容都被注释掉了,因为我收到了错误:
Everything commented out after the top was commented because I was getting the error:
警告 2 发现同一依赖程序集的不同版本之间存在无法解决的冲突.当日志详细程度设置为详细时,这些引用冲突会在构建日志中列出.
摆脱硬绑定就是解决这个问题.
and getting rid of the hard bindings was fixing that.
推荐答案
它需要 system.web.http.webhost,它是这个包的一部分.我通过安装以下软件包解决了这个问题:
It needs the system.web.http.webhost which is part of this package. I fixed this by installing the following package:
PM> Install-Package Microsoft.AspNet.WebApi.WebHost
或在 nuget 中搜索 https://www.nuget.org/packages/Microsoft.AspNet.WebApi.WebHost/5.1.0
or search for it in nuget https://www.nuget.org/packages/Microsoft.AspNet.WebApi.WebHost/5.1.0
这篇关于Web API 2 和 .NET 4.5.1 迁移后 GlobalConfiguration.Configure() 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!