A few days ago, Microsoft released .NET Core 3.0, and one of the biggest enhancements is support for Windows desktop applications (Windows only). By using the .NET Core 3.0 SDK Windows Desktop Component, you can port Windows Forms and Windows Presentation Foundation (WPF) applications. To be clear, Windows desktop components are supported and included only on Windows.
SDK download address:The hyperlink login is visible.
Links to introduce .NET Core features:
The hyperlink login is visible.
The hyperlink login is visible.
Features include the following:
- Use C# to build rich, interactive client web apps.
- Use gRPC to create high-performance backend services.
- SignalR now supports automatic reconnection and client-to-server flows.
- Use OpenAPI documentation to generate strongly typed client code for Web APIs.
- Endpoint routing is integrated through the framework.
- Kestrel has HTTP/2 enabled by default.
- Integrated web API and single-page app authentication support.
- Certificates and Kerberos authentication are supported.
- Integrate the new System.Text.Json serializer.
- The new universal hosting sets up common managed services such as dependency injection, configuration, and logging.
- A new Worker Service template for building long-term services.
- New EventCounters are created for requests per second, total, current, and failed requests.
- Startup errors hosted in IIS are now reported to the Windows Event Log.
- Request pipeline integration System.IO.Pipelines.
- Performance improvements across the entire technology stack.
Let's create a new .NET Core 3.0 console project with VS 2019, as shown in the figure below:
Referencing the Newtonsoft.Json package, write a few lines of code, as follows:
We right-click on VS Regenerate, then open the bin directory of the project, and find that several files will be generated, including :demo1.exe and Newtonsoft.Json.dll files.
Publish a single-file executable
Method 1:
Run the following command in the project directory:
We open the C:\Users\itsvse_pc\source\repos\demo1\demo1\bin\Debug\netcoreapp3.0\win10-x64 folder, and we will find that many dll files are generated and there is a publish folder.
Go to the publish folder,The size of the viewing demo1.exe is 66M, which is the same size as all files outside the folder, as shown in the figure below:
The generated single executable file actually contains the environment required for the execution of the program, and does not require the target computer to install the SDK, and the disadvantage is that the file size will become very large.
Method 2:
Right-click vs edit the project file and add the PublishSingleFile node configuration, the code is as follows:
Then right-click and click the "Publish" button.
Assembly links
The .NET core 3.0 SDK comes with a tool that can reduce the size of your app by analyzing IL and clipping unused assemblies.
Self-contained apps include everything you need to run code without having to install .NET on your main computer. However, many times the app only needs a fraction of the framework to run, and other unused libraries can be removed.
.NET Core now includes a setting that scans your app's IL using the IL linker tool. This tool will detect which code is required and then clip unused libraries. This tool can significantly reduce the deployment size of some applications.
To enable this tool, use the <PublishTrimmed> settings in your project and publish a self-contained app:
.NET Core CLI
We just generated a 66M file, and after adding the configuration,It became 35M, reducing the occupancy of 30M。
Be sure to consider applications or frameworks that use reflections or related dynamic features (including ASP.NET Core and WPF)Usually damaged during cutting。 This corruption occurs because the linker is unaware of this dynamic behavior and cannot determine which frame types are required for reflection。 The IL linker tool can be configured to spot this situation.
Most importantly, be sure to apply it after cuttingConduct tests。
(End)
|