.netCore System.Drawing.Common 发布,在CentOS 运行报错

centos下要运行 System.Drawing.Common ,需要先安装 mono的  libgdiplus 插件才可以。

安装后,还报以下错误的,才是下文的内容。

 

报错:

System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information

 

 

解决:

构建项目时,会在输出目录中生成[appname].runtimeconfig.json文件,只需要修改该配置文件即可

例如 生成的 Test.Api.runtimeconfig.json 文件

 

{

  "runtimeOptions": {

    "configProperties": {     

      "System.Drawing.EnableUnixSupport": true 

    }

  }

}

没有的话加上, "System.Drawing.EnableUnixSupport": true 

 

实际情况是我们不可能每次发布都去编辑发布后的这个文件,所以我们可以按照以下配置:

编辑项目文件 (*.csproj):
打开你的项目文件,并添加或修改 ItemGroup 中的 RuntimeHostConfigurationOption 项来包含所需的配置。

 

<ItemGroup>  
  <RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />  
</ItemGroup>

然后,重新发布就可以了

posted @   黄明辉  阅读(230)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示