【问题标题】:Deploying in azure error Could not resolve this reference. Could not locate the assembly System.Web.Http, Version=4.0.0.0在 azure 中部署错误无法解析此引用。找不到程序集 System.Web.Http,版本=4.0.0.0
【发布时间】:2015-06-15 11:07:50
【问题描述】:
我正在尝试在 Azure 中部署网站,但出现此错误:
D:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5):警告 MSB3245:无法解析此引用。找不到程序集“System.Web.Http,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL”。检查以确保该程序集存在于磁盘上。如果您的代码需要此引用,您可能会遇到编译错误。 [D:\home\site\repository\src\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj]
Mvc\Api\AuthorizeApiAttribute.cs(13,53):错误 CS0234:命名空间“System.Web”中不存在类型或命名空间名称“Http”(您是否缺少程序集引用?)
我检查并在解决方案中激活了“复制本地”选项。知道有什么问题吗?
【问题讨论】:
标签:
c#
asp.net-mvc-4
azure
asp.net-web-api
asp.net-web-api2
【解决方案1】:
检查Web.Config 并确保您正在加载正确的版本,并确保您在.NET 4.0 或NuGet Microsoft.AspNet.WebApi.Core 中引用System.Net.Http.dll。您使用的版本必须与您在web.config 中的版本相匹配。
例如Microsoft.AspNet.WebApi.Core 5.2.3 的 Nuget 可能有 System.Web.Http 之类的:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
【解决方案2】:
确保您对 System.Net.Http.dll 的引用来自与其他库相同的来源。这应该是您要添加到的项目的 bin 文件夹。
还要确保您的 packages.config 文件具有该库的引用:
<?xml version="1.0" encoding="utf-8"?>
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="System.Net.Http" version="4.0.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
</packages>
如果没有,请使用正确的目标框架如上所示添加它。
我相信 .NET 框架的更新版本(大于 4.0)已内置 System.Net.Http。如果这是一个选项,您可以简单地升级 .NET 版本。