问题描述
我是一个长期的WPF(.Net Framework)开发人员,最终我第一次将脚趾插入.Net Core.我目前正在尝试将小型v4.7.2 WPF应用程序转换为.Net Core 3.1.该解决方案包含一个WPF应用程序项目和一个类库项目,每个项目只有少数几个类,因此我认为创建一个包含WPF应用程序和类库项目(均为.Net Core 3.1)的新解决方案会更容易,然后复制原始解决方案中的cs和xaml文件.但是我似乎是第一个障碍...
I'm a long time WPF (.Net Framework) developer finally dipping my toes into .Net Core for the first time. I'm currently trying to convert a small v4.7.2 WPF application to .Net Core 3.1. The solution contains a WPF app project and a class library project, with only a handful of classes each, so I decided it would be easier to create a new solution containing a WPF app and class library project (both .Net Core 3.1), then copy the cs and xaml files from the original solution. However I seem to be falling at the first hurdle...
许多类使用来自 System.Windows
命名空间的类型(和 System.Windows.Media
, System.Windows.Controls
,ETC).这些可以在WPF应用程序项目中很好地解决,但不能在类库中解决.我注意到WPF应用程序项目对框架"Microsoft.WindowsDesktop.App.Wpf"的引用,但是类库项目却没有,我认为这是我的问题.但是我一生都无法弄清楚如何将这个框架添加到项目中.我该怎么做?!
Many of the classes use types from the System.Windows
namespace (and System.Windows.Media
, System.Windows.Controls
, etc). These resolve fine in the WPF app project but not the class library. I've noticed the WPF app project has a reference to the framework "Microsoft.WindowsDesktop.App.Wpf", but the class library project doesn't, which I assume is my problem. However I can't for the life of me figure out how to add this framework into the project. How do I do it?!
我在其他地方看到了将< UseWPF> true</UseWPF>
添加到类lib csproj文件的解决方案,但这没有效果.
I've seen solutions elsewhere of adding <UseWPF>true</UseWPF>
to the class lib csproj file, but this has no effect.
推荐答案
和往常一样,发布问题的时间不得早于找到答案的时间.我还必须将csproj文件中的SDK更改为:
As usual, no sooner do I post the question than I find the answer. I also had to change the SDK in the csproj file to:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
这篇关于如何在.Net Core中引用System.Windows命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!