如何在.NET Core类库中使用System.Windows.Forms [英] How to use System.Windows.Forms in .NET Core class library

查看:71
本文介绍了如何在.NET Core类库中使用System.Windows.Forms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了 .NET Core 类库并尝试针对 net40 框架构建它.我想使用 System.Windows.Forms 程序集中的 Clipboard 类.我该怎么做?

I've created .NET Core class library and try to build it against net40 framework. I want to use Clipboard class from System.Windows.Forms assembly. How can I do this?

我的 project.json 文件:

My project.json file:

{
    "version": "1.0.0-*",

    "dependencies": {
        "NETStandard.Library": "1.6.0"
    },

    "frameworks": {
        "netstandard1.6": {
            "imports": "dnxcore50",
            "buildOptions": {
                "define": [
                    "NETCORE"
                ]
            },
            "dependencies": {
                "System.Threading": "4.0.11",
                "System.Threading.Thread": "4.0.0",
                "System.Threading.Tasks":  "4.0.11"
                }
        },
        "net40": {
            "buildOptions": {
                "define": [
                    "NET40"
                    ]
                },
            "dependencies": {
                // dependency should be here but there is no such dll
            }
        }
    }
}

我所有的 net40 特定代码都在 NET40 定义下.有什么想法吗?

All my net40 specific code is under NET40 define. Any thoughts?

推荐答案

您需要的是 "frameworkAssemblies",例如:

What you need is "frameworkAssemblies", for example:

"frameworks": {
  "netstandard1.6": {
    "dependencies": {
      "NETStandard.Library": "1.6.0"
    }
  },
  "net40": {
    "frameworkAssemblies": {
      "System.Windows.Forms": {}
    }
  }
}

使用Clipboard也需要设置主线程为STA,所以不要忘记在Main()中添加[STAThread]在您的应用程序中.

Working with Clipboard also requires setting the main thread as STA, so don't forget to add [STAThread] to Main() in your application.

这篇关于如何在.NET Core类库中使用System.Windows.Forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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