pantonis
pantonis

Reputation: 6467

.NET Core and System.Drawing

I am trying to reference System.Drawing in a .NET Core console application targeting .NET 4.6, but the assembly is not there.

According to Microsoft, if you use .NET Core, System.Drawing is not available. But if you reference the full .NET framework, you should be able to use it.

This is my project.json file:

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

    "dependencies": {

    },

  "frameworks": {
    "net46": {
    }
  }
}

What is the problem?

Upvotes: 32

Views: 61118

Answers (6)

infl3x
infl3x

Reputation: 1572

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/

Upvotes: 30

Hesham Yemen
Hesham Yemen

Reputation: 854

For .NET 6 Core:

install Aspose.Drawing.Common

Upvotes: -3

kurdemol94
kurdemol94

Reputation: 604

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 package, so that you don't have to install the dependencies manually.

Upvotes: 0

Nikolay Pakudin
Nikolay Pakudin

Reputation: 680

Add the NuGet reference Microsoft.Windows.Compatibility.

Notice: mark "Include prerelease"

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

Upvotes: 28

guest
guest

Reputation: 41

When you want to use ASP.NET Core on the .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",
      }
    }
  }
}

Upvotes: 4

J. Doe
J. Doe

Reputation: 2747

System.Drawing is not a good option with ASP.NET.

If you want graphics manipulation, I suggest to use ImageSharp on .NET Core or ImageProcessor / ImageResizer on .NET Framework.

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

Upvotes: 19

Related Questions