1. 程式人生 > >.NET Core 跨平臺發布Linux和OSX

.NET Core 跨平臺發布Linux和OSX

option install www tco rar req curl all depend

跨平臺發布

簡單新建一個項目。

mkdir dotnethello

cd dotnethello

dotnet 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 跨平臺。

原文 http://www.linuxidc.com/Linux/2016-07/133202.htm 作者:linezero

.NET Core 跨平臺發布Linux和OSX