.net core桌面_适用于Windows桌面的.NET Core 3

.net core桌面

  • UI-dense forms over data (FOD) applications

    UI密集数据表单(FOD)应用程序
  • Responsive low-latency UI

    响应式低延迟UI
  • Applications that need to run offline/disconnected

    需要脱机/断开连接运行的应用程序
  • Applications with dependencies on custom device drivers

    依赖于自定义设备驱动程序的应用程序

This is just the beginning for Windows application development on .NET Core. Read on to learn more about the benefits of .NET Core for building Windows applications.

这只是.NET Core上Windows应用程序开发的开始。 继续阅读以了解有关.NET Core对构建Windows应用程序的好处的更多信息。

为什么在.NET Core上使用Windows桌面? (Why Windows desktop on .NET Core?)

.NET Core (and in the future .NET 5 that is built on top of .NET Core) will be the future of .NET. We are committed to support .NET Framework for years to come, however it will not be receiving any new features, those will only be added to .NET Core (and eventually .NET 5). To improve Windows desktop stacks and enable .NET desktop developers to benefit from all the updates of the future, we brought Windows Forms and WPF to .NET Core. They will still remain Windows-only technologies because there are tightly coupled dependencies to Windows APIs. But .NET Core, besides being cross-platform, has many other features that can enhance desktop applications.

.NET Core(以及将来在.NET Core之上构建的.NET 5)将是.NET的未来。 我们致力于在未来几年内支持.NET Framework,但是它将不会收到任何新功能,这些新功能只会被添加到.NET Core(最终是.NET 5)中。 为了改进Windows桌面堆栈,并使.NET桌面开发人员能够从将来的所有更新中受益,我们将Windows窗体和WPF引入了.NET Core。 它们仍将是仅Windows技术,因为与Windows API紧密相关。 但是.NET Core除了可以跨平台使用外,还具有许多其他功能,可以增强桌面应用程序。

First of all, all the runtime improvements and language features will be added only to .NET Core and in the future to .NET 5. A good example here is C# 8 that became available in .NET Core 3.0. Besides, the .NET Core versions of Windows Forms and WPF will become a part of the .NET 5 platform. So, by porting your application to .NET Core today you are preparing them for .NET 5.

首先,所有运行时改进和语言功能将仅添加到.NET Core中,将来也将添加到.NET 5中。一个很好的例子是C#8,它已在.NET Core 3.0中可用。 此外,Windows窗体和WPF的.NET Core版本将成为.NET 5平台的一部分。 因此,通过今天将您的应用程序移植到.NET Core,您正在为.NET 5准备它们。

Also, .NET Core brings deployment flexibility for your applications with new options that are not available in .NET Framework, such as:

此外,.NET Core还具有.NET Framework中不可用的新选项,为您的应用程序提供了部署灵活性,例如:

  • Side-by-side deployment. Now you can have multiple .NET Core versions on the same machine and can choose which version each of your apps should target.

    并行部署。 现在,您可以在同一台计算机上拥有多个.NET Core版本,并且可以选择每个应用程序应定位的版本。
  • Self-contained deployment. You can deploy the .NET Core platform with your applications and become completely independent of your end users environment – your app has everything it needs to run on any Windows machine.

    独立部署。 您可以与应用程序一起部署.NET Core平台,并完全独立于最终用户环境-您的应用程序具有在任何Windows计算机上运行所需的一切。
  • Smaller app sizes. In .NET Core 3 we introduced a new feature called linker (also sometimes referred to as trimmer), that will analyze your code and include in your self-contained deployment only those assemblies from .NET Core that are needed for your application. That way all platform parts that are not used for your case will be trimmed out.

    应用尺寸较小。 在.NET Core 3中,我们引入了一个称为链接器(有时也称为修剪器)的新功能,该功能将分析您的代码并将仅.NET Core中的程序集所需的程序集包括在自包含的部署中。 这样,所有未用于您的机箱的平台部件都将被修剪掉。
  • Single .exe files. You can package your app and the .NET Core platform all in one .exe file.

    单个.exe文件。 您可以将应用程序和.NET Core平台打包在一个.exe文件中。
  • Improved runtime performance. .NET Core has many performance optimizations compared to .NET Framework. When you think about the history of .NET Core, built initially for web and server workloads, it helps to understand if your application may see noticeable benefits from the runtime optimizations. Specifically, desktop applications with heavy dependencies on File I/O, networking, and database operations will likely see improvements to performance for those scenarios. Some areas where you may not notice much change are in UI rendering performance or application startup performance.

    改进的运行时性能。 与.NET Framework相比,.NET Core具有许多性能优化。 当您考虑最初为Web和服务器工作负载构建的.NET Core的历史时,它有助于了解您的应用程序是否可能从运行时优化中看到明显的好处。 特别是,在很大程度上依赖于文件I / O,网络和数据库操作的桌面应用程序可能会看到这些方案的性能提高。 您可能不会注意到很大变化的某些方面是UI渲染性能或应用程序启动性能。

By setting the properties <PublishSingleFile><RuntimeIdentifier> and <PublishTrimmed> in the publishing profile you’ll be able to deploy a trimmed self-contained application as a single .exe file as it is shown in the example below.

通过在发布配置文件中设置属性<PublishSingleFile><RuntimeIdentifier><PublishTrimmed> ,您将能够将修剪后的自包含应用程序部署为单个.exe文件,如下面的示例所示。

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

.NET Framework桌面和.NET Core桌面之间的区别 (Differences between .NET Framework desktop and .NET Core desktop)

While developing desktop applications, you won’t notice much difference between .NET Framework and .NET Core versions of WPF and Windows Forms. A part of our effort was to provide a functional parity between these platforms in the desktop area and enhance the .NET Core experience in the future. WPF applications are fully supported on .NET Core and ready for you to use, while we are working on minor updates and improvements. For Windows Forms the runtime part is fully ported to .NET Core and the team is working on the Windows Forms Designer. We are planning to get it ready by the fourth quarter of 2020 and for now you can check out the Preview version of the designer in Visual Studio 16.4 Preview 3 or later. Don’t forget to set the checkbox in the Tools->Options->Preview Features->Use the Preview of Windows Forms designer for .NET Core apps and restart the Visual Studio. Please keep in mind that the experience is limited for now since the work on it is in progress.

在开发桌面应用程序时,您不会注意到.NET Framework和WPF和Windows Forms的.NET Core版本之间的差异。 我们的工作之一是在台式机领域在这些平台之间提供功能对等,并在将来增强.NET Core的体验。 .NET Core完全支持WPF应用程序,并且在我们进行较小的更新和改进时,您可以使用它。 对于Windows窗体,运行时部分已完全移植到.NET Core,并且团队正在Windows窗体设计器上工作。 我们计划在2020年第四季度之前将其准备就绪,现在您可以在Visual Studio 16.4 Preview 3或更高版本中签出设计器的Preview版本。 不要忘记在“工具”->“选项”->“预览功能”->“。NET Core应用程序的Windows窗体设计器预览”中设置复选框,然后重新启动Visual Studio。 请记住,由于工作正在进行中,因此目前经验有限。

重大变化 (Breaking changes)

There are a few breaking changes between .NET Framework and .NET Core but most of the code related to Windows Forms and WPF areas was ported to Core as-is. If you were using such components as WCF Client, Code Access Security, App Domains, Interop and Remoting, you will need to refactor your code if you want to switch to .NET Core.

.NET Framework和.NET Core之间有一些重大更改 ,但是与Windows Forms和WPF区域相关的大多数代码都按原样移植到了Core。 如果使用的组件包括WCF客户端,代码访问安全性,应用程序域,互操作和远程处理,则要转换到.NET Core,则需要重构代码。

Another thing to keep in mind – the default output paths on .NET Core is different from on .NET Framework, so if you have some assumptions in your code about file/folder structure of the running app then it’ll probably fail at runtime.

请记住另一件事– .NET Core上的默认输出路径与.NET Framework上的默认输出路径不同,因此,如果您在代码中对正在运行的应用程序的文件/文件夹结构进行了一些假设,则它可能会在运行时失败。

Also, there are changes in how you configure the .NET features. .NET Core instead of machine.config file uses <something>.runtimeconfig.json file that comes with an application and has the same general purpose and similar information. Some configurations such as system.diagnosticssystem.net, or system.servicemodel are not supported, so an app config file will fail to load if it contains any of these sections. This change affects System.Diagnostics tracing and WCF client scenarios which were commonly configured using XML configuration previously. In .NET Core you’ll need to configure them in code instead. To change behaviors without recompiling, consider setting up tracing and WCF types using values loaded from a Microsoft.Extensions.Configuration source or from appSettings.

此外,配置.NET功能的方式也有所变化。 .NET Core而不是machine.config文件使用与应用程序一起提供的<something>.runtimeconfig.json文件,并且具有相同的通用目的和相似的信息。 不支持某些配置,例如system.diagnosticssystem.netsystem.servicemodel ,因此,如果应用程序配置文件包含以下任何部分,则将无法加载。 此更改会影响以前使用XML配置通常配置的System.Diagnostics跟踪和WCF客户端方案。 在.NET Core中,您需要改为在代码中进行配置。 若要更改行为而无需重新编译,请考虑使用从Microsoft.Extensions.Configuration源或appSettings加载的值来设置跟踪和WCF类型。

You can find more information on differences between .NET Core and .NET Framework in the documentation.

您可以在文档中找到有关.NET Core和.NET Framework之间差异的更多信息。

入门 (Getting Started)

Check out these short video tutorials:

查看这些简短的视频教程:

从.NET Framework移植到.NET Core (Porting from .NET Framework to .NET Core)

First of all, run the Portability Analyzer and if needed, update your code to get a 100% compatibility with .NET Core. Here are instructions on using the Portability Analyzer. We recommend to use a source control or to backup your code before you make any changes to your application in case the refactoring would not go the way you want, and you decide to go back to your initial state.

首先,运行可移植性分析器,并在需要时更新代码以与.NET Core达成100%的兼容性。 以下是有关使用可移植性分析器的说明 。 我们建议您在对应用程序进行任何更改之前使用源代码控制或备份代码,以防重构无法按照您想要的方式进行,并且您决定返回到初始状态。

When your application is fully compatible with .NET Core, you are ready to port it. As a starting point, you can try out a tool we created to help automate converting your .NET Framework project(s) to .NET Core – try-convert.

当您的应用程序与.NET Core完全兼容时,就可以准备移植它了。 首先,您可以尝试使用我们创建的工具以帮助将.NET Framework项目自动转换为.NET Core – try-convert

It’s important to remember that this tool is just a starting point in your journey to .NET Core. It is also not a supported Microsoft product. Although it can help you with some of the mechanical aspects of migration, it will not handle all scenarios or project types. If your solution has projects that the tool rejects or fails to convert, you’ll have to port by hand. No worries, we have plenty of tutorials on how to do it (in the end of this section).

重要的是要记住,该工具只是通往.NET Core的起点。 它也不是受支持的Microsoft产品。 尽管它可以帮助您解决迁移的某些机械问题,但是它不能处理所有方案或项目类型。 如果您的解决方案包含该工具拒绝或无法转换的项目,则必须手动进行移植。 不用担心,我们有很多关于如何执行此操作的教程(在本节的最后)。

The try-convert tool will attempt to migrate your old-style project files to the new SDK-style and retarget applicable projects to .NET Core. For your libraries we leave it up to you to make a call regarding the platform: weather you’d like to target .NET Core or .NET Standard. You can specify it in your project file by updating the value for <TargetFramework>. Libraries without .NET Core-specific dependencies like WPF or Windows Forms may benefit from targeting .NET Standard:

尝试转换工具将尝试将旧样式的项目文件迁移到新的SDK样式,并将适用的项目重新定位到.NET Core。 对于您的库,我们可以根据您的平台打电话:您希望以.NET Core或.NET Standard为目标的天气。 您可以通过更新<TargetFramework>的值在项目文件中指定它。 不具有.NET Core特定依赖性的库(例如WPF或Windows Forms)可以受益于.NET Standard:

<TargetFramework>netstandard2.1</TargetFramework>

so that they can be used by callers targeting many different .NET Platforms. On the other hand, if a library uses a feature that requires .NET Core (like Windows desktop UI APIs), it’s fine for the library to target .NET Core:

以便面向许多不同.NET平台的调用者可以使用它们。 另一方面,如果库使用需要.NET Core的功能(例如Windows桌面UI API),则可以将库定位为.NET Core:

<TargetFramework>netcoreapp3.0</TargetFramework>

try-convert is a global tool that you can install on your machine, then you can call from CLI:

try-convert是可以在计算机上安装的全局工具,然后可以从CLI调用:

C:\> try-convert -p <path to your project>

or

要么

C:\> try-convert -w <path to your solution>

As previously mentioned, if the try-convert tool did not work for you, here are materials on how to port your application by hand.

如前所述,如果try-convert工具对您不起作用,那么这里是有关如何手动移植应用程序的材料。

影片 (Videos)

文献资料 (Documentation)

翻译自: https://habr.com/en/company/microsoft/blog/475064/

.net core桌面

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值