asp.net-core - 如何在 Asp.Net Core 3 中访问 System.Drawing 即 System.Drawing.Common

标签 asp.net-core nuget system.drawing asp.net-core-3.0

我正在将面向完整框架的 Asp.Net Core 2.2 网站转换为面向 .Net Core 3.1 的 Asp.Net Core 3.1 应用程序。我有点不清楚与 System.Drawing 相关的依赖关系以及如何实现它们。

我的项目使用 System.Drawing,在 Asp.Net Core 3.1 下编译时出现此错误,提示我添加了对 System.Drawing.Common.dll 的引用。 :

Error CS1069: The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. 1-wwwGiftOasis3 C:\Users\Ron\source\repos\wwwGiftOasis3\wwwGiftOasis3\site\seller\profile\about\s-photos.cs



在 Visual Studio 中,我没有看到直接向裸 System.Drawing.Common.dll 添加引用的方法所以我假设我应该通过 NuGet 添加引用。

在 NuGet 中,我看到一个 System.Drawing.Common看起来像我想要的包,但我不清楚我的项目是否满足依赖项:

enter image description here

我的项目显示了这些依赖项:

enter image description here

所以我有几个与这一切相关的问题:

1) 我的项目是否依赖于框架 Microsoft.NETCore.App完成 NuGet 包的 Microsoft.NETCore.Platforms依赖?

2) 我打算只在 Windows 上运行这个 Asp.Net Core 3.1 网站这一事实是否符合 NuGet 包的 Microsoft.Win32.SystemEvents依赖?

最佳答案

System.Drawing使用特定于 Windows 的 API,因此与跨平台的 .NET Core 不兼容。微软创建 System.Drawing.Common作为 System.Drawing 的就地替代品对于 .NET 核心。它是一个精确的 API 替代品,但以跨平台的方式执行图像操作,而不是特定于 Windows 的方式。

总而言之,是的,您只需将 NuGet 放入您的项目中,然后前往镇上即可。您无需担心其他任何事情。

关于asp.net-core - 如何在 Asp.Net Core 3 中访问 System.Drawing 即 System.Drawing.Common,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59324386/

相关文章:

c# - 创建使用服务的新 AuthorizationHandler/IAuthorizationRequirement

visual-studio - 在不覆盖现有事件的情况下添加构建后事件

c# - 如何在 .NET 位图上使用 GDI+ 模糊效果?

c# - 为字母绘制矩形框

c# - asp.net core 中的常规默认路由不起作用

asp.net - 指定的 CGI 应用程序遇到错误,服务器终止了该进程

.net - 从 AWS lambda 中的 nodejs 执行 dotnet core 1.0 控制台应用程序时出错

visual-studio - Nuget软件包管理器更新3.1.1.0已损坏

Azure DevOps 构建管道不包含所有 NuGet 包内容文件

vb.net - 如何使用 system.drawing.stringformat 获得垂直 nowrap 字符串