.Net Native:让Win10应用更快更轻便的新框架
近日,微软在其Windows博客中通过一篇博文详细解释了.Net Native,这是用于开发Win10应用商店应用的全新框架,微软向开发者展示了为何.Net Native更优秀。

Net Native优点:
- 冷启动性能可提升60飈i>
- 热启动性能可提升40飈i>
- 本地编译,应用占用内存会更少
- 不在依赖桌面.NET运行库
- 由于应用是被编译到本地代码的,因此能够得到本地代码的性能(类比C 程序)
- 你仍然可以使用业内先进的C#或VB编程语言及其配套工具
.Net Native 运行时:
.Net Native 提供了普通模式和cpp模式:
普通模式 类似现有的uwp .Net Native,将IL直接编译成机器码然后与运行库链接。
cpp模式 将IL编译成c 源码,然后使用c 编译器编译,类似于unity3d的IL2CPP,这种方式将具有很好的跨平台前景。
以下是Linux Ubuntu 14.04尝试过程(Windows下失败):
安装方法mono
安装必要工具
-
- 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<br>
- cd dotnetcli<br>
- wget https://dotnetcli.blob.core.windows.net/dotnet/dev/Installers/Latest/dotnet-linux-x64.latest.deb<br>
- dpkg -i dotnet-linux-x64.latest.deb<br>
- apt-get -y -f install<br>
复制代码
然后设置环境变量(如需重新启动可用,可以写入/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 普通模式编译
使用.Net Native cpp模式编译
-
- dotnet compile --native --cpp
复制代码
没有错误则代表成功,可以运行测试
-
- cd /root/core/samples/helloworld/bin/Debug/dnxcore50/native
- ls
- ./helloworld
复制代码
总结
微软通用应用,即能够在桌面PC、平板、手机以及Xbox等Windows10设备中运行的通用应用都是基于.Net Native编写的。对开发者来说,.Net Native是熟悉但又更快的编程框架;对最终用户来说,不需要再安装.Net框架即可使用UWP通用应用。应用也将更加轻便,且运行速度更快(相比.Net应用)
|