分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

.NET Core 跨平台发布Linux和OSX

发布时间:2023-09-06 01:15责任编辑:蔡小小关键词:.NETLinux

跨平台发布

简单新建一个项目。

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 跨平台。

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

.NET Core 跨平台发布Linux和OSX

原文地址:http://www.cnblogs.com/caipz/p/7625708.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved