本文介绍了之后的Web API 2和.NET 4.5.1迁移GlobalConfiguration.Configure()不是present的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始跟随this指南迁移我的项目.NET 4.5.1和网页API 2。

I recently started following this guide to migrate my project to .NET 4.5.1 and Web Api 2.

的第一件事MS开发商里克·安德森让你做的就是变化:

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不包含配置

目前我的项目是MVC的5和网页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.

我该如何去修复呢?

感谢您。

编辑:

下面是我的组装绑定:

<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

这篇关于之后的Web API 2和.NET 4.5.1迁移GlobalConfiguration.Configure()不是present的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 03:44