如何在.NET Core类库中使用System.Windows.Forms [英] How to use System.Windows.Forms in .NET Core class library
本文介绍了如何在.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": {}
}
}
}
使用剪贴板
还需要将主线程设置为STA,因此不要忘记将 [STAThread]
添加到 Main()
在您的应用程序中。
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屋!
查看全文