【问题标题】:SignalR with vNextSignalR 与 vNext
【发布时间】:2015-04-22 10:25:47
【问题描述】:

我很难在 vNext 项目(epmty 模板)中使用 SignalR。

首先我将 SignalR.Server 依赖项添加到我的 project.json 文件中,现在看起来像这样:

{
    "webroot": ".",
    "dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
        "Microsoft.AspNet.StaticFiles": "1.0.0-*",
        "Microsoft.AspNet.SignalR.Server": "3.0.0-*",
        "Serilog": "1.4.113.0"
},
    "commands": {
        "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5002"
    },
    "frameworks": {
        "dnx451": {
            "dependencies": {
                "Microsoft.Framework.Logging.Serilog": "1.0.0-*"
            }
        },
        "dnxcore50": { }
    }
}

然后我想在我的 Startup.cs 中映射 SignalR(因为我在 git 的某个地方找到了)

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddSignalR(options =>
        {
            options.Hubs.EnableDetailedErrors = true;
        });
    }

    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
#if DNX451
        string OutputTemplate = "{SourceContext} {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";

        var serilog = new LoggerConfiguration()
            .MinimumLevel.Verbose()
            .WriteTo.RollingFile(@".\SignalR-Log-{Date}.txt", outputTemplate: OutputTemplate);

        loggerFactory.AddSerilog(serilog);
#endif

        app.UseFileServer();

        app.UseSignalR<RawConnection>("/raw-connection");
        app.UseSignalR();
    }

,但是当我在顶部添加时:

using Microsoft.AspNet.SignalR;

我得到错误:

命名空间中不存在类型或命名空间名称“SignalR”>“Microsoft.AspNet”(您是否缺少程序集引用?) VersaWeb.ASP.NET >5.0 c:\Users\Jakub\documents\visual studio >2015\Projects\VersaWeb\src\VersaWeb\Startup.cs

我现在被卡住了。


编辑:

问题必须与project.json有关,因为当我从音乐商店复制一个时,问题就消失了。

这是我当前的 project.json(可能不需要一些依赖项,所以我将进一步测试它)

{
"authors": [
    "author"
],
"description": "your description here",
"version": "1.0.0",
"compilationOptions": { "warningsAsErrors": true, "define": [ "DEMO", "TESTING" ] },
"code": [
    "**/*.cs"
],
"bundleExclude": "*.cmd",
"webroot": "wwwroot",
"dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta3",
    "EntityFramework.InMemory": "7.0.0-beta3", // For Mono.
    "Kestrel": "1.0.0-beta3",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta3",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta3",
    "Microsoft.AspNet.Mvc": "6.0.0-beta3",
    "Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-beta3",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
    "Microsoft.AspNet.SignalR.Server": "3.0.0-beta3",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
    "Microsoft.Framework.Cache.Memory": "1.0.0-beta3",
    "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta3",
    "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta3",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta3"
},
"commands": {
    "gen": "Microsoft.Framework.CodeGeneration",
    "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004",
    "run": "run server.urls=http://localhost:5003",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002"
},
"frameworks": {
    "aspnet50": { },
    "aspnetcore50": { }
}
}

【问题讨论】:

  • 也许该错误仅适用于 dnxcore?尝试在 project.json 中注释掉 ""dnxcore50": { }" 以验证这一点。此外,请查看使用 SignalR 的 MusicStore sample。我也在我的 vnext 项目中使用 SignalR(虽然使用 kre,而不是新的 dnx 东西),所以它绝对是可行的。
  • 我评论了 dnxcore50 并没有发生任何事情,但现在我已经下载了音乐商店,我将检查并将我的文件与商店进行比较
  • MusicStore 示例作品 - 并且根据 Web 控制台 Web 套接字已正确打开 - 我现在将检查代码
  • @qbik - 你现在可以写回复,我将标记为 answere - 音乐商店样本对我帮助很大 :) 谢谢
  • 太棒了!你能写一下,你的项目出了什么问题,有什么帮助吗?

标签: c# asp.net signalr asp.net-core


【解决方案1】:

结帐MusicStore sample,它使用 SignalR。我还在我的 vnext 项目中使用 SignalR(虽然使用 kre,而不是新的 dnx 东西),所以它绝对是可行的。

【讨论】:

【解决方案2】:

查看您最初的 project.json,这可能是因为您试图以 dnx451 为目标,但运行的是错误的 .NET 开发运行时。

我在使用 vNext 时发现的主要问题是您的所有引用都需要在同一级别 beta3/beta4/beta5 并且您的 .NET 运行时必须匹配 (frameworksproject.json)。我相信beta3 使用了aspnet50,并且由于beta4 重命名它现在是dnx451

值得在命令行上运行 dnvm list 并查看已安装的内容以及设置为“默认”别名的内容,因为这是 Visual Studio 在运行应用程序时将使用的内容(除非在解决方案中覆盖 global.json文件)。

【讨论】:

    猜你喜欢
    • 2016-03-01
    • 2020-03-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多