First, preface
. NET Toolchain in the latest Preview3 release, the new MSBuild project system was introduced, and the project files were returned to the . csproj XML file to manage, project files, package references, assembly references,. NET Core toolset, publish content definitions, and more. This article will mainly discuss how to publish the executable file in the new project system (. csproj). We all know that in previous releases, project files were managed by Project.json files to manage project and package references, then by removing dependencies---Microsoft.NETCore.App- > "type": "Platform" child node, and define the runtimes node to publish the executable file.
The executable is the file on the target machine that you do not need to install the . NET Core SDK or any runtime. For example, you can generate Coreapp.exe executable files on Windows, and in Linux you can use./coreapp to execute.
The principle of such an executable, is to use a C + + application as a carrier (host), load CoreCLR, through the CoreCLR and then load any assembly, interested friends here can also go to GitHub to see CoreCLR Part of the Clrhost.
Second, generate executable
In the new . csproj project file , we want to publish an executable file by manually creating a node named <RuntimeIdentifiers>, under which the node is added runtimeidentifiers that is, the previous rid definition, the RID is a unified naming label that describes the system platform. For example, the target system platform for the executable file I want to publish is defined as Win10 and Mac os 10.11.* as follows:
<PropertyGroup> <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers> </ Propertygroup>
Publish the target executables for each platform using the following command:
dotnet build-r win10-x64dotnet build-r osx.10.11-x64
The above command generates a debug version with symbol files and debug information, and your application will be generated in the .\bin\debug\netcoreapp1.0\< runtime_identifier> directory. If you want to build the final version of your production environment, get it by using the following command:
dotnet publish-c release-r win10-x64dotnet publish-c release-r osx.10.11-x64
Release version target execution files generated by the above command will be generated in the .\bin\release\netcoreapp1.0\<runtime_identifier> directory, and each target platform directory has generated executables, published project assemblies,. NET core dependencies, or necessary files and so on to ensure that the generator can be executed independently.
Let's look at a complete definition of a new csproj file:
<project toolsversion= "15.0" xmlns= "http://schemas.microsoft.com/developer/msbuild/2003" > <import Project = "$ (msbuildextensionspath) \$ (msbuildtoolsversion) \microsoft.common.props"/> <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 Include= "**\*.cs"/> <embeddedresource include= "**\*.resx"/> </ItemGroup> <ItemGroup> <pa Ckagereference include= "Microsoft.NETCore.App" > <Version>1.0.1</Version> </PackageReference> <packagereference include= "Newtonsoft.json" > <Version>9.0.1</Version> </packagereference& Gt <packagereference include= "MICROSOFT.NET.SDK" > <verSion>1.0.0-alpha-20161102-2</version> <PrivateAssets>All</PrivateAssets> </ packagereference> </ItemGroup> <import project= "$ (MSBuildToolsPath) \microsoft.csharp.targets"/> </Project>
Third, RID
RIDs are abbreviations for runtime identifier, which are used to define target operating system markings. The RID is constantly updated and we can find the RID definition in the COREFX project, and the commonly used RIDs are as follows:
Windows RIDs
Windows 7/windows Server R2
Windows 8/windows Server 2012
win8-x64
win8-x86
win8-arm
Windows 8.1/windows Server R2
win81-x64
win81-x86
win81-arm
Windows 10/windows Server 2016
win10-x64
win10-x86
win10-arm
win10-arm64
Linux RIDs
OS X RIDs
osx.10.10-x64
osx.10.11-x64
osx.10.12-x64
Iv. system Dependence
Publish the target platform executable file, also need to rely on the system characteristics, next we see what the system needs components:
Windows |
Ubuntu |
Centos |
OS X |
|
-
Libunwind8
-
Libunwind8-de V
-
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
|
|