是否可以将.NET Core与BackgroundWorker类一起使用? [英] Is it possible to use BackgroundWorker class with .net core?

查看:43
本文介绍了是否可以将.NET Core与BackgroundWorker类一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在Windows上可以正常运行的C#控制台项目移植到具有.NET Core的Linux上.我已经创建了一个project.json文件,运行dotnet restore,一切似乎都可以正常工作.但是,当我运行dotnet build时,会收到以下消息:

I am trying to port a C# console project that works fine on Windows to Linux with .NET Core. I have created a project.json file, run dotnet restore and everything seems to work fine. But when I run dotnet build, I get this message :

找不到类型或名称空间名称"BackgroundWorker"(是您缺少using指令或程序集引用吗?)

The type or namespace name 'BackgroundWorker' could not be found (are you missing a using directive or an assembly reference?)

根据 .NET Core API ,System.ComponentModel中似乎存在BackgroundWorker类.

According to .NET Core API, the class BackgroundWorker seems to exist in System.ComponentModel.

这是我的project.json:

Here's my project.json :

"version": "1.0.0-*",
  "buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  }

我想念什么吗?

谢谢!

推荐答案

您需要将 System.ComponentModel.EventBasedAsync nuget包作为依赖项包括在内(而不是 System.ComponentModel nuget包).如果您查看GitHub 上的BackgroundWorker.cs文件,您可以看到它嵌套在 System.ComponentModel.EventBasedAsync 命名空间下.

You need to include the System.ComponentModel.EventBasedAsync nuget package as a dependency (not the System.ComponentModel nuget package). If you look at the BackgroundWorker.cs file on GitHub, you can see that it's nested under the System.ComponentModel.EventBasedAsync namespace.

您的project.json如下所示:

Your project.json would look like this:

  "version": "1.0.0-*",
  "buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        },
        "System.ComponentModel.EventBasedAsync": "4.3.0"
      },
      "imports": "dnxcore50"
    }
  }

这篇关于是否可以将.NET Core与BackgroundWorker类一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆