分享

Centos7中部署Net6.0程序

 _src_ 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)icon-default.png?t=M4ADhttps://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:///dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=centos.7-x64

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多