c# - 缺少对程序集的引用

标签 c# .net-core

我正在尝试创建套接字服务器,但我遇到了不确定如何解决的问题。

这是我用于我的 project.json 的内容:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "vtortola.WebSocketListener": "2.2.0.2"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "net45"
    }
  }
}

然后我有了这个基本脚本 Server.cs:

using System.Net;
using vtortola.WebSockets;

public class Server {

    public static void Main(string[] args){

        var server = new WebSocketListener(new IPEndPoint(IPAddress.Any, 8006));
        var rfc = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(server);
        server.Standards.RegisterStandard(rfc);
        server.Start();

    }

}

当我运行以下命令时:

master@ubuntu:~/Documents/Chat$ dotnet run

我收到以下错误:

Project Chat (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling Chat for .NETCoreApp,Version=v1.0
/usr/share/dotnet/dotnet compile-csc @/home/master/Documents/Chat/obj/Debug/netcoreapp1.0/dotnet-compile.rsp returned Exit Code 1
/home/master/Documents/Chat/Server.cs(8,26): error CS0012: The type 'IPEndPoint' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
/home/master/Documents/Chat/Server.cs(10,26): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
/home/master/Documents/Chat/Server.cs(11,16): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Compilation failed.
0 Warning(s)
3 Error(s)

Time elapsed 00:00:02.6995789

最佳答案

您不能将 net45 导入到 netcoreapp1.0 中,那是行不通的。当您指定 imports 时,您基本上是在说:“我知道那些包声称它们不兼容,但我保证它们是兼容的”。

vtortola.WebSocketListener 只支持 net45,所以你不能在 .Net Core 上使用它(尽管你仍然可以在 dotnet CLI 上使用它,如果您将框架更改为 net451)。

但似乎有一个 vtortola.WebSocketListener.dnx 包的 beta 版本,它支持 dnxcore50(.Net Core 的先前预发布版本)。导入它(连同 microsoft.Tpl.Dataflow 依赖项的 portable-net45+win8)应该可以工作。 project.json 将如下所示:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "vtortola.WebSocketListener.dnx": "2.2.0.1-beta-00002"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "dnxcore50", "portable-net45+win8" ]
    }
  }
}

It seems vtortola.WebSocketListener will also support RC2 directly in the future.

关于c# - 缺少对程序集的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37555294/

相关文章:

c# - AddSingleton 与异步调用?

c# - 如何更改 WinForms 上下文菜单上复选标记或 'more' 箭头的颜色?

c# - 仿函数和 "generics"有什么区别

c# - System.Data.Objects.MaterializedDataRecord 不包含属性

c# - dotnet 工具 aspnet-codegenerator 在错误的路径中查找可执行文件

c# - Web api dotnet 核心中 Api 版本控制错误的自定义错误响应

c# - 协助打开从 C# VSTO Excel 项目到关闭的 .xlsx 文件的连接(不打开 .xlsx 文件)

c# - 为什么我的 MenuStrip 在第一次点击时出现在错误的位置?

caching - Gitlab CI 和 .NET Core - 无法通过 2 阶段构建获取 nuget 缓存

c# - 在不同的 .NET 框架之间共享记录器