.NET Core 跨平台發布(dotnet publish)

來源:互聯網
上載者:User

標籤:get   lin   map   conf   time   sof   uil   pyc   發布   

.NET Core 跨平台發布(dotnet publish) ,無需安裝.NET Core SDK,就可以運行。

前面講解了.NET Core 的VSCode 開發。現在來講講發布(dotnet publish)。

.NET Core and ASP.NET Core 1.0 RC2 runtime and libraries 在五月中旬發布。

.NET Core and ASP.NET Core 1.0 RTM (release) runtime and libraries  六月底發布。

https://blogs.msdn.microsoft.com/dotnet/2016/05/06/net-core-rc2-improvements-schedule-and-roadmap/

跨平台發布

簡單建立一個項目。

mkdir dotnethellocd dotnethellodotnet new

 

dotnet new之後 修改project.json 如下:

{  "version": "1.0.0-*",  "buildOptions": {    "emitEntryPoint": true  },  "dependencies": {    "Microsoft.NETCore.App": {      "type": "platform", //去掉      "version": "1.0.0-rc2-*"    }  },  "frameworks": {    "netcoreapp1.0": {      "imports": "dnxcore50"    }  },  "runtimes":{//加入runtime    "win7-x64": { },    "win7-x86": { },    "osx.10.10-x64": { },    "osx.10.11-x64": { },    "ubuntu.14.04-x64":{ }  }}

添加NuGet.Config

<?xml version="1.0" encoding="utf-8"?><configuration>  <packageSources>    <clear />    <add key="AspNetCI" value="https://www.myget.org/F/aspnetcirelease/api/v3/index.json" />    <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />  </packageSources></configuration>

dotnet restore

還原以後就可以編譯發布了。

 

Windows:

這裡預設輸入 dotnet publish 會發布 win7-x64 。

我們定位到 win7-x64\publish 檔案夾,可以直接執行 dotnethello.exe ,無需安裝.netcore sdk 。

 

Ubuntu:

我們要發布到linux ubuntu 直接指定 runtime 。

dotnet publish -r ubuntu.14.04-x64

把發布檔案夾(ubuntu.14.04-x64/publish)拷貝到ubuntu上。

直接就可以執行,不需要安裝.netcore sdk,只需.netcore依賴的幾個包:

https://github.com/dotnet/cli/blob/rel/1.0.0/Documentation/cli-prerequisites.md 

Ubuntu distributions require the following libraries installed:

  • libunwind8
  • libunwind8-dev
  • gettext
  • libicu-dev
  • liblttng-ust-dev
  • libcurl4-openssl-dev
  • libssl-dev
  • uuid-dev
  • unzip

 

設定檔案夾下的執行檔案dotnethello 設定好許可權以後直接 ./dotnethello

 

Mac OS:

同理mac os 一樣,指定osx runtime。

dotnet publish -r osx.10.10-x64

將 osx.10.10-x64/publish 拷貝到mac os 。

OS X 需要安裝libssl

OS X requires the following libraries and versions installed:

  • libssl 1.1

執行dotnethello

這樣我們無需安裝.NET Core SDK 就可以運行.NET Core 應用程式。實現了.NET Core 跨平台。

 

如果你覺得本文對你有協助,請點擊“推薦”,謝謝。

 

.NET Core 跨平台發布(dotnet publish)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.