.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,不過相信很快就可以全面使用,因為開發已接近尾聲,現在問題在工具之前的配合


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM