在 .Net Core 类库中使用 Windows 窗体 - .NET Core 控件库 [英] Use Windows Forms in a .Net Core Class Library - .NET Core Control Library

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

问题描述

我正在尝试创建一个引用 .net core 3 版本的 winform 的 .net core 3 类库(因此该程序集本身可以被 .net core 3 WinForm 程序集引用).

I am trying to create a .net core 3 class library that references the .net core 3 version of winform (so this assembly can itself be referenced by a .net core 3 WinForm assembly).

一个新的 .net core WinForm 项目引用了 Microsoft.WindowsDesktop.App.WindowsForms,但是我找不到任何具有该名称的 nuget 包.

A new .net core WinForm project references Microsoft.WindowsDesktop.App.WindowsForms, however I can't find any nuget package with that name.

我需要做什么来引用 .net core 3 winform?

What do I need to do to reference the .net core 3 winform?

推荐答案

更新:在 VS 2019 的更高版本中(我尝试了 16.8.2 版),有一个用于 .NET Core 的 Windows 窗体控件库的项目模板.>

Update: In later versions of VS 2019 (I tried Version 16.8.2) there is a project template for Windows Forms Control Library for .NET Core.

目前Windows Forms .NET Core 处于预览模式,我不知道任何官方的 Nuget 包或 VS 2019 16.2.2 中 .NET Core 中 Windows 窗体控件库的项目模板.

Currently Windows Forms .NET Core is in Preview mode and I don't know any official Nuget package or Project template for Windows Forms Control Library in .NET Core in VS 2019 16.2.2.

但是要创建Windows 窗体控件库,您可以使用以下说明:

But to create a Windows Forms Control Library, you can use the following instructions:

  1. 添加类型为 Class Library (.NET Core)
  2. 的新项目
  3. 项目创建后,右键单击项目文件并选择Edit Project File
  4. 将项目 SDK 更改为
  5. 通过添加 true 将 Windows 窗体指定为 UI 技术.

现在项目文件应该如下所示:

Now the project file should be like the following:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
</Project>

现在您可以向该项目添加诸如 FormUserControl 之类的 Windows 表单元素,并且可以毫无问题地构建项目.

Now you can add Windows forms elements like Form or UserControl to this project and build the project without any problem.

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

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