打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Centos7中部署Net6.0程序
userphoto

2023.01.25 四川

关注

一、第一种方法

添加仓储指令

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

二、第二种方法

去微软官网找到下载链接Download .NET 6.0 (Linux, macOS, and Windows)

https://dotnet.microsoft.com/en-us/download/dotnet/6.0

wget 

  1. sudo mkdir dotnet
  2. sudo tar zxvf dotnet-sdk-6.0.101-linux-x64.tar.gz -C dotnet

修改环境变量

vi /etc/profile

在文件尾部添加

  1. export PATH=$PATH:/data/dotnet
  2. export DOTNET_ROOT=/data/dotnet

测试dotnet --info

三、程序需改

判断运行环境是不是windows

  1. bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
  2. string filePath = string.Empty;
  3. if (isWindows)
  4. {
  5. filePath = "c:/" + name;
  6. }
  7. else
  8. {
  9. filePath = "/" + name;
  10. }

四、运行程序

dotnet 程序名.dll

出现以下信息,是因为没有装aspnetcore的运行时,运行yum install aspnetcore-runtime-6.0即可

  1. It was not possible to find any compatible framework version
  2. The framework 'Microsoft.AspNetCore.App', version '6.0.0' (x64) was not found.
  3. - No frameworks were found.

  4. You can resolve the problem by installing the specified framework and/or SDK.

  5. The specified framework can be found at:
  6. - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=centos.7-x64
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
DotNet Core 多平台开发体验
Setup Factory 7.0 打包.netframework 2.0
ASP.NET 5是如何通过XRE实现跨平台的
.NET 架构开发 应知应会
Linux - CentOS 7 安装 .Net Core 运行环境
ASP.NET Core在CentOS上的最小化部署实践
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服