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>
然后,重新发布就可以了