.NET Core and System.Drawing

前端 未结 5 1626
孤城傲影
孤城傲影 2020-12-01 07:53

I am trying to reference System.Drawing in a .net core console app targeting net46 but the assembly is not there. According to MS if you use dotnetcore System.Drawing is not

相关标签:
5条回答
  • 2020-12-01 08:29

    When you want to use asp.net core on .NET Full Framework only you can reference the old class libraries like this

    {
      "version": "1.0.0-*",
    
      "frameworks": {
        "net452": {
          "dependencies": {
          },
          "frameworkAssemblies": {
            "System.Drawing": "4.0.0.0",
          }
    
    
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-01 08:34

    Add NuGet reference Microsoft.Windows.Compatibility

    Notice: mark "Include prerelease"

    Of course, it works only if prerelease packages are OK for you.

    0 讨论(0)
  • 2020-12-01 08:35

    I was able to replace System.Drawing with a multi-platform library called SkiaSharp. IF you're running on linux, you can also install this nuget so that you don't have to install the dependencies manually.

    0 讨论(0)
  • 2020-12-01 08:46

    I know this is old, but there is now a port of the library called System.Drawing.Common. Try installing that one with NuGet.

    To make this possible, there is a metapackage called Windows Compatibility Pack. However, this metapackage includes many, many Windows related APIs (distributed as packages).

    Source: https://developers.de/2018/01/22/how-to-use-system-drawing-in-net-core/

    0 讨论(0)
  • 2020-12-01 08:48

    System.Drawing is not a good option with ASP.NET (more here: http://www.asprangers.com/post/2012/03/23/Why-you-should-not-use-SystemDrawing-from-ASPNET-applications.aspx)

    If you want graphics manipulation i suggest to use ImageSharp (https://github.com/JimBobSquarePants/ImageSharp) on .Net Core or ImageProcessor (http://imageprocessor.org/) / ImageResizer (https://imageresizing.net/) on .Net Framework

    Also, if you really need to use System.Drawing change frameworks in your project.json to netstandard1.6 and add in dependencies "NETStandard.Library": "1.6.1"

    0 讨论(0)
提交回复
热议问题