首页 技术 正文
技术 2022年11月18日
0 收藏 368 点赞 3,600 浏览 2013 个字

.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

https://github.com/dotnet/core/blob/master/Documentation/prereqs.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

CentOS:

CentOS distributions require the following libraries installed:

  • deltarpm
  • epel-release
  • unzip
  • libunwind
  • gettext
  • libcurl-devel
  • openssl-devel
  • zlib
  • libicu-devel

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

如果你觉得本文对你有帮助,请点击“推荐”,谢谢。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919