


How .NET Core publishes executable files in the new project system (.csproj)
一、前言
.NET工具链在最新的Preview3版本中,引入了新的MSBuild项目系统,项目文件又回归了.csproj的XML文件来管理,项目文件、包引用、程序集引用、.NET Core工具集、发布内容定义等内容。本文主要将主要讨论如何在新的项目系统中(.csproj)发布可执行文件。我们都知道在之前的版本中,项目文件是通过project.json文件来管理项目和包引用的,那么通过删除 dependencies->Microsoft.NETCore.App-> "type": "platform" 子节点,并定义runtimes节点,来发布可执行文件 。
所为可执行文件就是在目标机器上,不需要安装.NET Core SDK或任何Runtime,就可以执行的文件。比如在Windows上可以生成 coreapp.exe的可执行文件,而在Linux中可以使用 ./coreapp 来执行。
原理上这种可执行文件,就是通过一个C++应用程序为载体(宿主),加载CoreCLR,通过CoreCLR再加载任意的程序集,对这里有兴趣的朋友也可以到Github上去看一下CoreCLR中ClrHost的部分。
二、生成可执行
在新的.csproj项目文件中,我们要想发布一个可执行文件,就在手动创建名为
<propertygroup> <runtimeidentifiers>win10-x64;osx.10.11-x64</runtimeidentifiers> </propertygroup>
通过如下命令发布各平台的目标可执行文件:
dotnet build -r win10-x64 dotnet build -r osx.10.11-x64
上面的命令可以生成带有符号文件和调试信息的DEBUG版本,你的应用程序将生成在.\bin\Debug\netcoreapp1.0\目录下,如果想生成生产环境的最终版本请通过如下命令获取:
dotnet publish -c release -r win10-x64 dotnet publish -c release -r osx.10.11-x64
通过上述命令生成的Release版本目标执行文件将生成在 .\bin\release\netcoreapp1.0\
我们来看一个新的csproj文件的完整定义:
<project> <import></import> <propertygroup> <outputtype>Exe</outputtype> <targetframework>netcoreapp1.0</targetframework> <versionprefix>1.0.0</versionprefix> <debugtype>Portable</debugtype> <runtimeidentifiers>win10-x64;osx.10.11-x64</runtimeidentifiers> </propertygroup> <itemgroup> <compile></compile> <embeddedresource></embeddedresource> </itemgroup> <itemgroup> <packagereference> <version>1.0.1</version> </packagereference> <packagereference> <version>9.0.1</version> </packagereference> <packagereference> <version>1.0.0-alpha-20161102-2</version> <privateassets>All</privateassets> </packagereference> </itemgroup> <import></import> </project>
三、RID
RID是Runtime Identifier的缩写,它用于定义目标操作系统标示。RID会不断的更新,我们可以在CoreFx项目中找到RID定义,常用的RID有如下:
Windows RIDs
Windows 7 / Windows Server 2008 R2
win7-x64
win7-x86
Windows 8 / Windows Server 2012
win8-x64
win8-x86
win8-arm
Windows 8.1 / Windows Server 2012 R2
win81-x64
win81-x86
win81-arm
Windows 10 / Windows Server 2016
win10-x64
win10-x86
win10-arm
win10-arm64
Linux RIDs
Red Hat Enterprise Linux
rhel.7.0-x64
rhel.7.1-x64
rhel.7.2-x64
Ubuntu
ubuntu.14.04-x64
ubuntu.14.10-x64
ubuntu.15.04-x64
ubuntu.15.10-x64
ubuntu.16.04-x64
##ubuntu.16.10-x64
- CentOS
- ##centos.7-x64
-
##fedora.24-x64 -
OpenSUSE - ##opensuse.13.2-x64
##opensuse .42.1-x64
##Oracle Linux
- ol.7.0-x64
-
##Currently supported Ubuntu derivatives -
linuxmint.17-x64 - linuxmint.17.1-x64
-
linuxmint.17.2-x64 ##linuxmint.17.3-x64
linuxmint. 18-x64
-
OS X RIDs ##osx.10.10-x64
- ##debian.8-x64
- fedora.23-x64
osx.10.11-x64
osx.10.12-x64
4. System dependencies
The released target platform executable file also needs to rely on system features. Next, let’s take a look at the system. What are the required components:
##Ubuntu
CentOSOS X | ##Visual C++ Redistributable | for Visual Studio 2015 |
|
|
|
libunwind
|
|
The above is the detailed content of How .NET Core publishes executable files in the new project system (.csproj). For more information, please follow other related articles on the PHP Chinese website!

C# and .NET provide powerful features and an efficient development environment. 1) C# is a modern, object-oriented programming language that combines the power of C and the simplicity of Java. 2) The .NET framework is a platform for building and running applications, supporting multiple programming languages. 3) Classes and objects in C# are the core of object-oriented programming. Classes define data and behaviors, and objects are instances of classes. 4) The garbage collection mechanism of .NET automatically manages memory to simplify the work of developers. 5) C# and .NET provide powerful file operation functions, supporting synchronous and asynchronous programming. 6) Common errors can be solved through debugger, logging and exception handling. 7) Performance optimization and best practices include using StringBuild

.NETFramework is a cross-language, cross-platform development platform that provides a consistent programming model and a powerful runtime environment. 1) It consists of CLR and FCL, which manages memory and threads, and FCL provides pre-built functions. 2) Examples of usage include reading files and LINQ queries. 3) Common errors involve unhandled exceptions and memory leaks, and need to be resolved using debugging tools. 4) Performance optimization can be achieved through asynchronous programming and caching, and maintaining code readability and maintainability is the key.

Reasons for C#.NET to remain lasting attractive include its excellent performance, rich ecosystem, strong community support and cross-platform development capabilities. 1) Excellent performance and is suitable for enterprise-level application and game development; 2) The .NET framework provides a wide range of class libraries and tools to support a variety of development fields; 3) It has an active developer community and rich learning resources; 4) .NETCore realizes cross-platform development and expands application scenarios.

Design patterns in C#.NET include Singleton patterns and dependency injection. 1.Singleton mode ensures that there is only one instance of the class, which is suitable for scenarios where global access points are required, but attention should be paid to thread safety and abuse issues. 2. Dependency injection improves code flexibility and testability by injecting dependencies. It is often used for constructor injection, but it is necessary to avoid excessive use to increase complexity.

C#.NET is widely used in the modern world in the fields of game development, financial services, the Internet of Things and cloud computing. 1) In game development, use C# to program through the Unity engine. 2) In the field of financial services, C#.NET is used to develop high-performance trading systems and data analysis tools. 3) In terms of IoT and cloud computing, C#.NET provides support through Azure services to develop device control logic and data processing.

.NETFrameworkisWindows-centric,while.NETCore/5/6supportscross-platformdevelopment.1).NETFramework,since2002,isidealforWindowsapplicationsbutlimitedincross-platformcapabilities.2).NETCore,from2016,anditsevolutions(.NET5/6)offerbetterperformance,cross-

The C#.NET developer community provides rich resources and support, including: 1. Microsoft's official documents, 2. Community forums such as StackOverflow and Reddit, and 3. Open source projects on GitHub. These resources help developers improve their programming skills from basic learning to advanced applications.

The advantages of C#.NET include: 1) Language features, such as asynchronous programming simplifies development; 2) Performance and reliability, improving efficiency through JIT compilation and garbage collection mechanisms; 3) Cross-platform support, .NETCore expands application scenarios; 4) A wide range of practical applications, with outstanding performance from the Web to desktop and game development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
