无法将标准.Net参考添加到项目

时间:2019-03-15 16:01:10

标签: asp.net-core

如何添加标准的.Net参考,例如

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

尝试时

using (System.Drawing.Image I)

我收到错误

Severity    Description File    Line
Error   The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcdxxxxx' Consider adding a reference to that assembly.

参考时,VS 2018希望我指向DLL文件。 真令人沮丧。这是一个基于Asp.NetCore MVC Web的项目。

1 个答案:

答案 0 :(得分:3)

System.Drawing与.NET Core不兼容,因为它使用了.NET Core中不提供的Windows特定的API。此后,Microsoft已经发布了System.Drawing.Common,这是一个NuGet软件包,提供了与旧System.Drawing类似的API,但使用了跨平台的API。为了真正替代它,System.Drawing名称空间现在转发到System.Drawing.Common,因此较旧的代码无需更改即可工作。

总之,您需要在项目中添加System.Drawing.Common NuGet软件包。