coreRT 和 Native 编译netcore AOT程序

AOT是预编译成本地程序,避免JIT动态编译存在的性能问题。linux

netcore一个吸引人的项目,就是基于coreRt 运行时的本地编译技术,下面我来替你们尝试一下它究竟表现如何。c++

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <RestoreSources>https://dotnet.myget.org/F/dotnet-core/api/v3/index.json</RestoreSources>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="microsoft.dotnet.ilcompiler" Version="1.0.0-alpha-*" />

  </ItemGroup>

</Project>


首先要在项目文件添加相关的包源,也就是:json

<RestoreSources>https://dotnet.myget.org/F/dotnet-core/api/v3/index.json</RestoreSources>windows

而后引用包:api

<PackageReference Include="microsoft.dotnet.ilcompiler" Version="1.0.0-alpha-*" />app

由于尚未正式版,因此要把版本号写清楚,不然会提示找不到该包。性能

用命令发布:测试

dotnet publish -r win-x64 -c releasethis

会提示错误:error : Platform linker not found. To fix this problem, download and install Visual Studio 2017 from http://visualstudio.com. Make sure to install the Desktop Development for C++ workload.spa

微软就是喜欢这里一块那里一块,就不能好好提供一站式服务吗?没办法,下载安装c++ 环境。这个要4GB,不知道有什么越过的方法。

经测试,在win7 sp1 x64 虚拟机环境下能够正常执行。

image

hello world程序不到4m大小。感受还能够。

其余

只支持64位生成,并且不能交叉编译,也就是不能在windows编译linux程序。在win7下面测试成功,winxp提示不是有效32位(不知道在xp 64版会怎样)。不知道可否支持win vista。

ps。当这个native包更新后,他会替换默认的编译器,不知道怎么换回来。。

相关文章
相关标签/搜索