Centos7中部署Net6.0程序
原创
©著作权归作者所有:来自51CTO博客作者花开花落的个人博客的原创作品,请联系作者获取转载授权,否则将追究法律责任
一、第一种方法
添加仓储指令
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
执⾏安装命令:
1、如果不需要在linux上编译源码
yum install dotnet-runtime-6.0
2、如果需要在linux上编译源码
yum install dotnet-sdk-6.0
3、如果是有webapi接⼝或者⽹页
yum install aspnetcore-runtime-6.0
安装完成后输⼊指令
dotnet --info 查看是否安装正确
Centos7中安装Net5.0运⾏时,只需要把6.0替换为5.0
二、第二种方法
wget
sudo mkdir dotnet
sudo tar zxvf dotnet-sdk-6.0.101-linux-x64.tar.gz -C dotnet
修改环境变量
在文件尾部添加
export PATH=$PATH:/data/dotnet
export DOTNET_ROOT=/data/dotnet
测试dotnet --info
三、程序需改
判断运行环境是不是windows
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
string filePath = string.Empty;
if (isWindows)
{
filePath = "c:/" + name;
}
else
{
filePath = "/" + name;
}
四、运行程序
出现以下信息,是因为没有装aspnetcore的运行时,运行yum install aspnetcore-runtime-6.0即可
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '6.0.0' (x64) was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=centos.7-x64