Table of Contents
一、前言
二、生成可执行
三、RID
Home Backend Development C#.Net Tutorial How .NET Core publishes executable files in the new project system (.csproj)

How .NET Core publishes executable files in the new project system (.csproj)

Apr 23, 2017 pm 04:28 PM
executable file

一、前言

  .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项目文件中,我们要想发布一个可执行文件,就在手动创建名为的节点,在这个节点下面,添加RuntimeIdentifiers也就是以前的RID定义,RID是描述系统平台的统一命名标示。例如我想要发布的可执行文件的目标系统平台为Win10Mac os 10.11.* 定义如下:


 <propertygroup>
      <runtimeidentifiers>win10-x64;osx.10.11-x64</runtimeidentifiers>
 </propertygroup>
Copy after login


  通过如下命令发布各平台的目标可执行文件:


dotnet build -r win10-x64
dotnet build -r osx.10.11-x64
Copy after login


  上面的命令可以生成带有符号文件和调试信息的DEBUG版本,你的应用程序将生成在.\bin\Debug\netcoreapp1.0\目录下,如果想生成生产环境的最终版本请通过如下命令获取:


dotnet publish -c release -r win10-x64
dotnet publish -c release -r osx.10.11-x64
Copy after login


  通过上述命令生成的Release版本目标执行文件将生成在 .\bin\release\netcoreapp1.0\目录下,并且每一个目标平台目录下都有生成的可执行文件、发布项目的程序集、.NET Core依赖或必要的文件来保证生成程序的独立可执行。

  我们来看一个新的csproj文件的完整定义:

How .NET Core publishes executable files in the new project system (.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>
Copy after login

How .NET Core publishes executable files in the new project system (.csproj)

三、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

    Debian
    • ##debian.8-x64
    • Fedora
    • fedora.23-x64
    • ##fedora.24-x64
    • OpenSUSE
  • ##opensuse.13.2-x64
    • ##opensuse .42.1-x64

    • ##Oracle Linux

    ##ol.7-x64
    • ol.7.0-x64

    • ##ol.7.1-x64
    • ol.7.2-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

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:
  • Windows

##Ubuntu

CentOS
OS X ##Visual C++ Redistributable

for Visual Studio 2015

    libunwind8
  • libunwind8-dev
  • gettext
    libicu-dev
  • liblttng-ust-dev
  • libcurl4-openssl-dev
  • libssl-dev
  • uuid-dev
  • unzip
  • ##deltarpm
  • epel-release
  • unzip
libunwind
  • gettext
  • libcurl -devel
  • openssl-devel
  • zlib
  • libicu-devel
  • libssl version 1.0.1

  • ##

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Declaration of Independence for Python Applications: PyInstaller's Road to Freedom Declaration of Independence for Python Applications: PyInstaller's Road to Freedom Feb 20, 2024 am 09:27 AM

PyInstaller: Independence of Python applications PyInstaller is an open source python packaging tool that packages Python applications and their dependencies into an independent executable file. This process eliminates dependence on the Python interpreter while allowing applications to run on a variety of platforms, including Windows, MacOS, and Linux. Packaging Process The packaging process of PyInstaller is relatively simple and involves the following steps: pipinstallpyinstallerpyinstaller--onefile--windowedmain.py--onefile option creates a single

What is a linux executable file? What is a linux executable file? Mar 09, 2023 am 10:00 AM

In Linux, an executable file means that the file can be run and the file has "x" permissions; the executable file can be a code file (script file) or a binary file. There are two ways to run a file: 1. Use the interpreter to run the file directly; 2. Use "./" to run the file, and the syntax is "./ file name".

The ultimate evolution of Python applications: PyInstaller emerges from the cocoon and becomes a butterfly The ultimate evolution of Python applications: PyInstaller emerges from the cocoon and becomes a butterfly Feb 19, 2024 pm 03:27 PM

PyInstaller is a revolutionary tool that empowers Python applications beyond their original scripting form. By compiling Python code into standalone executable files, PyInstaller unlocks a new realm of code distribution, deployment, and maintenance. From a single script to a powerful application In the past, Python scripts only existed in a specific Python environment. Distributing such a script requires users to install Python and the necessary libraries, which is a time-consuming and cumbersome process. PyInstaller introduces the concept of packaging, combining Python code with all required dependencies into a single executable file. The Art of Code Packaging PyInstaller’s Work

Which command in Linux Which command in Linux Mar 21, 2024 am 09:50 AM

Title: Excerpt from LinuxWhichCommand: A practical tutorial with examples on using the &quot;which&quot; command on Linux and how to find various executables and scripts from the PATH variable. Permalink: linux-which-command Category: Linux Commands In this guide, we will learn about the “Which” command in Linux. Prerequisites: To perform the steps demonstrated in this guide, you need the following components: A properly configured Linux system. For testing purposes, it is recommended to use LinuxVM. Have a basic understanding of the command line interface which command. Modern Linux systems come with multiple tools built-in that can be used for various tasks such as system administration,

A dress-up party for Python code: PyInstaller's stylish butler A dress-up party for Python code: PyInstaller's stylish butler Feb 19, 2024 pm 06:39 PM

In the world of software development, packaging code into an executable file is a crucial step. For python developers, PyInstaller stands out as their stylish butler that transforms Python scripts into standalone and easy-to-deploy applications. The charm of PyInstaller PyInstaller is a powerful tool that can package Python code and its dependencies into a single executable file. It eliminates the tedious task of installing the Python interpreter and dependent libraries on the target machine, making application deployment a breeze. Packaging an application using PyInstaller To package an application using PyInstaller, follow the below

How to use PyCharm to package code into an executable file: Detailed explanation of project packaging techniques How to use PyCharm to package code into an executable file: Detailed explanation of project packaging techniques Feb 02, 2024 pm 09:20 PM

PyCharm project packaging skills: teach you how to package code into executable files Introduction: In the software development process, packaging code into executable files is a very important step. It allows our applications to run on different machines more easily, while also protecting our code from modification. This article will introduce how to use PyCharm to package Python code into an executable file and provide specific code examples. Text: 1. Install PyInstallerPyInstaller

PyCharm programming tips: package Python programs into independent executable files PyCharm programming tips: package Python programs into independent executable files Feb 21, 2024 am 08:54 AM

With the continuous development of Python programming, developers often face a question: How to package their Python programs into independent executable files for easy sharing and deployment? This involves an important skill in PyCharm: packaging Python programs. This article will share some PyCharm programming tips and teach you how to use PyCharm to package Python programs into independent executable files. Preparation Before starting, make sure you have installed PyCharm and the required third party

Super transformation of Python applications: PyInstaller's magic wand Super transformation of Python applications: PyInstaller's magic wand Feb 19, 2024 pm 04:39 PM

Python is a powerful programming language that is widely used in various fields. However, when you need to deploy your Python application to other computers, you will face the problem of non-executable scripts. To solve this problem, PyInstaller came into being. This is an excellent tool that converts Python scripts into standalone executable files, allowing your application to run on any computer without the need to install a Python interpreter. PyInstaller's magic transformation PyInstaller works simply and efficiently. It creates an executable file using Python code, required libraries and all dependencies. This executable contains all the necessary components of the application

See all articles