.NET Core和System.Drawing

pan*_*nis 16 .net c# .net-core asp.net-core

我试图在针对net46的.net核心控制台应用程序中引用System.Drawing,但程序集不在那里.根据MS,如果你使用dotnetcore System.Drawing不可用.但是,如果您引用完整的.net框架,您应该能够使用它

这是我的project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

    "dependencies": {

    },

  "frameworks": {
    "net46": {
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

不知道是什么问题

J. *_*Doe 11

System.Drawing对于ASP.NET来说不是一个好的选择(更多这里:http://www.asprangers.com/post/2012/03/23/Why-you-should-not-use-SystemDrawing-from-ASPNET-applications.aspx)

如果你想要图形操作我建议在.Net Core或ImageProcessor(http://imageprocessor.org/)/ ImageResizer(https://imageresizing.net/)上使用ImageSharp(https://github.com/JimBobSquarePants/ImageSharp)).Net Framework

此外,如果您确实需要System.Drawing在project.json中使用更改框架netstandard1.6并添加依赖项"NETStandard.Library": "1.6.1"


Nik*_*din 9

添加NuGet参考 Microsoft.Windows.Compatibility

注意:标记"包含预发布"

当然,它只适用于预发布包适合您.


inf*_*l3x 8

我知道这很旧,但是现在有一个名为的库端口System.Drawing.Common。尝试使用NuGet安装那个。

为了使之成为可能,有一个名为的元包Windows Compatibility Pack。但是,此元软件包包括许多与Windows相关的API(作为软件包分发)。

资料来源:https : //developers.de/2018/01/22/how-to-use-system-drawing-in-net-core/

  • System.Drawing.Common可在Windows,Linux和macOS上运行。在Linux和macOS上,您需要安装其本机依赖项ligdiplus。您可以执行`apt-get install -y libgdiplus`或`brew install mono-libgdiplus`。 (2认同)
  • Net Core 7 中的其他平台将不再支持它,仅供参考 (2认同)