【发布时间】:2020-04-20 08:31:00
【问题描述】:
我在 Visual Studio 2019 中有一个项目,我正在从 .NET Framework 4.6 迁移到 .NET Core 3.1。
我使用 Microsoft 的指南来移植我的项目,described here。 我运行了Portability Analyzer,它表明该项目是 100% 可移植的。
但是对 System.Windows 的每个依赖都不再起作用了。例如我使用System.Windows.Rect。在official documentation 中明确指出它适用于 .NET Core 3.1。
在代码中,它用“找不到类型或命名空间名称'Rect'(您是否缺少 using 指令或程序集引用?)”标记 Rect,并在顶部将我的 using System.Windows 标记为灰色消息“使用指令是不必要的”。
此错误适用于我的代码中的许多内容,例如 System.Windows.ResourceDictionary、System.Windows.Application.Current、System.Windows.Point、...
因此,由于某些原因,我似乎无法使用System.Windows,即使使用本身似乎工作正常。
我在 NuGet 包管理器中搜索了 System.Windows 和 googled it,但找不到任何东西。
所以这是我的问题:如何在带有 Visual Studio 2019 的 .NET Core 3.1 项目中使用 System.Windows?我目前的猜测是,我需要手动包含程序集WindowsBase.dll,但在我的安装目录(C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional)中,我只能在C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\LiveShare\Agent 找到一个,而且它似乎不是正确的。
【问题讨论】:
-
在您的 .proj 文件中,您使用的是
<Project Sdk="Microsoft.NET.Sdk">还是<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">? -
您是否在
csproj文件中设置了UseWPF=true属性? -
@RosdiKasim 我使用
<Project Sdk="Microsoft.NET.Sdk">的默认设置。 -
@PavelAnikhouski 我没有在我的 csproj 文件中设置
UseWPF,所以它仍然是默认值。 -
就图形点和矩形而言,Microsoft 已发布 System.Drawing.Common 以提供对 GDI+ 图形功能跨平台的访问。您可以通过 NuGet 安装 System.Drawing.Common。检查您是否已安装该库。
标签: c# .net-core visual-studio-2019 .net-core-3.1