asp.net-mvc 如何获得'System.Web.Http,版本=5.2.3.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28604325/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:24:22  来源:igfitidea点击:

How to get 'System.Web.Http, Version=5.2.3.0?

asp.net-mvcasp.net-mvc-5nuget

提问by John Hadikusumo

I just created an MVC5 project and added several packages from nuget, but then when I compiled the project, i got this error. It seems one of the packages really depends on system.web.http version 5.2.3.0, which i couldn't find anywhere. I just wonder how to get the latest version of system.web.http ?

我刚刚创建了一个 MVC5 项目并从 nuget 添加了几个包,但是当我编译该项目时,出现此错误。似乎其中一个软件包确实依赖于 system.web.http 版本 5.2.3.0,我在任何地方都找不到。我只是想知道如何获得最新版本的 system.web.http ?

Error   2   Assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
d:\Backup 2014-12-25\Website-Projects\www.ptsol.com.au\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll

回答by Roman Patutin

In Package Manager Console

在包管理器控制台中

Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3

Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3

回答by Bracher

One way to fix it is by modifying the assembly redirect in the web.config file.

修复它的一种方法是修改 web.config 文件中的程序集重定向。

Modify the following:

修改以下内容:

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

to

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="4.0.0.0" />
</dependentAssembly>

So the oldVersion attribute should change from "...-4.0.0.0" to "...-5.2.3.0".

因此 oldVersion 属性应从“...-4.0.0.0”更改为“...-5.2.3.0”。

回答by Bob Koury

I did Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3but it still did not work. Then looked in my project bin folder and saw that it still had the old System.Web.Mvc file.

我做到了,Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3但它仍然不起作用。然后查看我的项目 bin 文件夹,发现它仍然有旧的 System.Web.Mvc 文件。

So I manually copied the newer file from the package to the bin folder. Then I was up and running again.

所以我手动将较新的文件从包中复制到 bin 文件夹中。然后我又跑起来了。

回答by Vitali Siamenau

Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3

安装包 Microsoft.AspNet.WebApi.Core -version 5.2.3

Then in the project Add Reference -> Browse. Push the browse button and go to the C:\Users\UserName\Documents\Visual Studio 2015\Projects\ProjectName\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45 and add the needed .dll file

然后在项目中添加引用 -> 浏览。按浏览按钮并转到 C:\Users\UserName\Documents\Visual Studio 2015\Projects\ProjectName\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45 并添加所需的 .dll 文件

回答by Doug Wiley

The packages you installed introduced dependencies to version 5.2.3.0 dll's as user Bracher showed above. Microsoft.AspNet.WebApi.Cors is an example package. The path I take is to update the MVC project prtheitroadto any package installs:

您安装的软件包引入了对 5.2.3.0 版 dll 的依赖,如上图用户 Bracher 所示。Microsoft.AspNet.WebApi.Cors 是一个示例包。我采取的路径是将 MVC 项目更新为任何软件包安装:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3

https://www.nuget.org/packages/microsoft.aspnet.mvc

https://www.nuget.org/packages/microsoft.aspnet.mvc

回答by Ram Kishore K

Uninstalling and re-installing the NuGet package worked for me.

卸载并重新安装 NuGet 包对我有用。

  1. Remove any old reference from the project.
  1. 从项目中删除任何旧引用。

Execute this in the Package Manager Console:

在包管理器控制台中执行此操作:

  1. UnInstall-Package Microsoft.AspNet.WebApi.Core -version 5.2.3
  2. Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3
  1. UnInstall-Package Microsoft.AspNet.WebApi.Core -version 5.2.3
  2. Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3