coreRT 和 Native 编译netcore AOT程序

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

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

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


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

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

然后引用包:

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

因为还没有正式版,所以要把版本号写清楚,否则会提示找不到该包。

用命令发布:

dotnet publish -r win-x64 -c release

会提示错误: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.

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

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

image

hello world程序不到4m大小。感觉还可以。

其他

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

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

posted @ 2018-08-23 16:54  诺贝尔  阅读(1382)  评论(0编辑  收藏  举报