HTML5技术

.Net Native 跨平台尝试 - 非仙

字号+ 作者:H5之家 来源:博客园 2015-11-21 08:04 我要评论( )

微软平台的开源愈演愈烈,在前两天的Connect()上,不仅发布了最新的.Net Core RC1,而且进一步开源了.Net Native跨平台实现。 .Net Native 运行时: https://github.com/dotnet/corert .NET 命令行工具链: https://github.com/dotnet/cli .Net Native提供了

微软平台的开源愈演愈烈,在前两天的Connect()上,不仅发布了最新的.Net Core RC1,而且进一步开源了.Net Native跨平台实现。

.Net Native 运行时:

https://github.com/dotnet/corert

.NET 命令行工具链:

https://github.com/dotnet/cli

 

.Net Native提供了普通模式和cpp模式:

普通模式 类似现有的uwp .Net Native,将IL直接编译成机器码然后与运行库链接。

cpp模式 将IL编译成c++源码,然后使用c++编译器编译,类似于unity3d的IL2CPP,这种方式将具有很好的跨平台前景。

 

以下是Linux Ubuntu 14.04尝试过程(Windows下失败):

安装方法mono

https://github.com/dotnet/corert/blob/master/Documentation/prerequisites-for-building.md

安装必要工具

apt-get update apt-get -y install curl libicu-dev libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g apt-get -y install autoconf automake build-essential libtool

 

在cli项目中提供了deb安装包与tar.gz两种格式,我下载deb安装并修复依赖

mkdir dotnetcli
cd dotnetcli
wget https://dotnetcli.blob.core.windows.net/dotnet/dev/Installers/Latest/dotnet-linux-x64.latest.deb
dpkg -i dotnet-linux-x64.latest.deb
apt-get -y -f install

然后设置环境变量(如需重新启动可用,可以写入/etc/profile文件)

export DOTNET_HOME=/usr/share/dotnet

输入 dotnet 可以看到以下输出表示安装成功

.NET Command Line Interface Usage: dotnet [common-options] [command] [arguments] Arguments: [command] The command to execute [arguments] Arguments to pass to the command Common Options (passed before the command): -v|--verbose Enable verbose output Common Commands: compile Compiles a .NET project publish Publishes a .NET project for deployment run Compiles and immediately executes a .NET project

使用git 下载示例代码

cd /root
git clone https://github.com/dotnet/core.git

先恢复nuget包

cd /root/core/samples/helloworld dotnet restore

使用.Net Native 普通模式编译

dotnet compile --native

使用.Net Native cpp模式编译

dotnet compile --native --cpp

没有错误则代表成功,可以运行测试

cd /root/core/samples/helloworld/bin/Debug/dnxcore50/native
ls
./helloworld

可以看到成功输出

Hello World!

注意:当前.Net Native仅可以运行samples下的helloworld和dotnetbot,不过相信很快就可以全面使用,因为开发已接近尾声,现在问题在工具之前的配合

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • Dora.Interception: 一个为.NET Core度身定制的AOP框架 - Artech

    Dora.Interception: 一个为.NET Core度身定制的AOP框架 - Artech

    2017-05-02 11:00

  • 如何在 ASP.NET Core 中发送邮件 - Savorboard

    如何在 ASP.NET Core 中发送邮件 - Savorboard

    2017-05-02 08:02

  • 十二个 ASP.NET Core 例子 - Savorboard

    十二个 ASP.NET Core 例子 - Savorboard

    2017-04-27 16:01

  • ASP.NET MVC5请求管道和生命周期 - 雪飞鸿

    ASP.NET MVC5请求管道和生命周期 - 雪飞鸿

    2017-04-24 08:04

网友点评