无法将 Signalr 客户端库作为可移植库添加到 Xamarin 项目

Posted

技术标签:

【中文标题】无法将 Signalr 客户端库作为可移植库添加到 Xamarin 项目【英文标题】:Cannot add the Signalr Client library as a portable library to a Xamarin project 【发布时间】:2015-11-12 17:54:47 【问题描述】:

我尝试将 Signalr Client library 和 WebApi client 包添加到我的 Xamarin 解决方案(在具有 Xamarin 支持的 Visual Studio 和 Xamarin Studio 上)但我总是收到此错误,尽管我能够安装其他 PCL(对于例如 Microsoft.Net.Http):

Could not install package 'Microsoft.AspNet.WebApi.Client 5.2.3'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wpa81+wp80+Monoandroid10+xamarinios10+MonoTouch10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

以及添加 Signalr 时出现以下错误:

Adding Microsoft.AspNet.SignalR.Client...
Adding 'Microsoft.AspNet.SignalR.Client 2.2.0' to Corda.Client.
Could not install package 'Microsoft.AspNet.SignalR.Client 2.2.0'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

我也尝试过更改目标框架但没有成功。 这是我的项目的构建设置:

这是我的 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile259\SupportedFrameworks 文件夹:

我在 Mac OSX 和 Windows 10 上遇到相同的错误。有什么想法吗?

【问题讨论】:

【参考方案1】:

使用 Profile78 解决了我的问题。完整解释here。

【讨论】:

这对我没有帮助,最终做的是手动安装Droid项目中所有缺少的包依赖项,一个一个(有些需要其他依赖项的一部分,所以你可以跳过它们) 【参考方案2】:

一个简单的解决方法,适用于我的 Xamarin 与 VS:

    在此处手动下载 dll 文件:https://components.xamarin.com/gettingstarted/signalr/true 将以下内容导入您的解决方案。 Microsoft.AspNet.SignalR.Client.dll Newtonsoft.Json.dll System.Net.Http.Extensions.dll System.Net.Http.Primitives.dll 完成!

问题不在于 dll 文件,而在于 (nuget) 安装程序。

【讨论】:

【参考方案3】:

问题出在 nuget 包管理器上,特别是 Windows Phone 8.1 项目。我认为它希望它是一个 windows phone silverlight 8.1 项目。在 xamarin 项目中的通用 8.1 电话项目上安装 Signalr 客户端存在错误。它应该在下一个 xamarin 版本中进行整理。在便携式配置中取消选择 windows phone 8.1 解决了这个问题,这意味着您必须将 windows phone 8.1 项目从 xamarin 项目中取出,并且您需要创建一个通用 windows 10 项目。

【讨论】:

请查看URL,它将帮助您获得优质的内容【参考方案4】:

是的,正如其他人所建议的,这是 nuget 包管理器的问题,根据这个链接,它应该通过 Microsoft.signalr.client 2.2.1 版本的发布来修复,但现在如果你仍然想使用 nuget , 添加以下 nuget 源 https://www.myget.org/F/aspnetwebstacknightly/ 到 Visual Studio 并按照以下链接中的建议安装 Signalr 客户端 dll 的预发布版本 2.2.1 pre-160523-b816 https://github.com/SignalR/SignalR/issues/3393

【讨论】:

以上是关于无法将 Signalr 客户端库作为可移植库添加到 Xamarin 项目的主要内容,如果未能解决你的问题,请参考以下文章

SignalR的使用

使用可移植类库作为 COM 接口

ASP.NET Core SignalR :SignalR Javascript 客户端

SignalR 学习记录-简介

SignalR——聊天室的实现

SignalR v3.1.3.js [支持微信小程序]