1.一般在windows pc上使用vscode 开发好.netcore 程序如果需要发布到其他平台需要注意一些事情
首先需要明白2个概念:FDD(Framework-dependent deployment)和 SCD (Self-contained deployment)
2.# FDD
Framework-dependent deployment. As the name implies, framework-dependent deployment (FDD) relies on the presence of a shared system-wide version of .NET Core on the target system. Because .NET Core is already present, your app is also portable between installations of .NET Core. Your app contains only its own code and any third-party dependencies that are outside of the .NET Core libraries. FDDs contain .dll files that can be launched by using the dotnet utility from the command line. For example, dotnet app.dll runs an application named app.
3.#
SCD
Self-contained deployment. Unlike FDD, a self-contained deployment (SCD) doesn't rely on the presence of shared components on the target system. All components, including both the .NET Core libraries and the .NET Core runtime, are included with the application and are isolated from other .NET Core applications. SCDs include an executable (such as app.exe on Windows platforms for an application named app), which is a renamed version of the platform-specific .NET Core host, and a .dll file (such as app.dll), which is the actual application.
参考: https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli
参考: https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli
4.# RIDs
Windows RIDs
Windows 7 / Windows Server 2008 R2
win7-x64
win7-x86
Windows 8 / Windows Server 2012
win8-x64
win8-x86
win8-arm
Windows 8.1 / Windows Server 2012 R2
win81-x64
win81-x86
win81-arm
Windows 10 / Windows Server 2016
win10-x64
win10-x86
win10-arm
win10-arm64
Linux RIDs
Red Hat Enterprise Linux
rhel.7-x64
Ubuntu
ubuntu.14.04-x64
ubuntu.14.10-x64
ubuntu.15.04-x64
ubuntu.15.10-x64
ubuntu.16.04-x64
ubuntu.16.10-x64
CentOS
centos.7-x64
Debian
debian.8-x64
Fedora
fedora.23-x64
fedora.24-x64
OpenSUSE
opensuse.13.2-x64
opensuse.42.1-x64
Oracle Linux
ol.7-x64
ol.7.0-x64
ol.7.1-x64
ol.7.2-x64
Currently supported Ubuntu derivatives
linuxmint.17-x64
linuxmint.17.1-x64
linuxmint.17.2-x64
linuxmint.17.3-x64
linuxmint.18-x64
1
OS X RIDs
osx.10.10-x64
osx.10.11-x64
osx.10.12-x64
参考: https://docs.microsoft.com/zh-cn/dotnet/core/rid-catalog
参考: https://docs.microsoft.com/zh-cn/dotnet/core/rid-catalog
5.# 修改 .csproj 项目文件
<RuntimeIdentifiers>win7-x64;centos.7-x64</RuntimeIdentifiers>
完整如下图:
6.# 直接执行 build 如果依赖项目较多可能会等很久
先执行 dotnet restore 命令
这样会下载安装一些依赖项目等完成后
再执行 build 命令
测试下在 windows 下是 ok 的
最后执行publish 指令:
dotnet publish -c Release -r centos.7-x64
最后会生成Release版本:
最后生成文件非常多:
下一步使用FTP工具上传到 CentOS publish 目录:
最后一步使用 putty 命令执行就可以了
dotnet xxx.dll
--------------------------------------------------------------------------------------------------------------
注意事项 以上是基于 FDD模式 (感觉4G技术 娃哈哈哈哈)
要提前手工安装 .netcore 2.0 SDK
参考命令如下:
# 解压安装文件 $ tar -xzf ~/dotnet/dotnet-dev-centos-x64.1.0.0-preview1-002702.tar.gz # 软连接 ln -s /home/jake/leak/dotnet/dotnet /usr/local/bin # 删除软连接 rm -rf /usr/local/bin/dotnet # 查看版本 dotnet --version