wpf 错误:项目文件必须在参考列表中包含 .NET Framework 程序集“WindowsBase、PresentationCore、PresentationFramework”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10820241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:25:41  来源:igfitidea点击:

Error: Project file must include the .NET Framework assembly 'WindowsBase, PresentationCore, PresentationFramework' in the reference list

wpfwinforms

提问by user575219

I am using wpf in windows forms application, C#. Follow up of the question. Adding a collection of solid,dashed lines pen to a combo box

我在 Windows 窗体应用程序 C# 中使用 wpf。跟进问题。 将一组实线、虚线笔添加到组合框

Error: Project file must include the .NET Framework assembly 'WindowsBase, PresentationCore, PresentationFramework' in the reference list.

错误:项目文件必须在参考列表中包含 .NET Framework 程序集“WindowsBase、PresentationCore、PresentationFramework”。

Please suggest

请建议

Sun

太阳

回答by Rob Habraken

It's an old question, but for the purpose of keeping this resource a valid one: it is true that you can add references likes this, as Ross and Reed suggest, but I do not believe that this is the actual solution, you're just fixing the effect of an issue, not the cause.

这是一个老问题,但为了保持此资源的有效性:确实可以像罗斯和里德建议的那样添加这样的引用,但我不相信这是实际的解决方案,您只是解决问题的后果,而不是原因。

Exactly like @dumbledad says, I got the exact same error message when I included files in my project that got marked as a 'Page' in the .csproj file, resulting in Visual Studio wanting to compile this resource. However, this being an uncompilable resource (in my case it was a XAML file, could be an image as well) Visual Studio asks for extra assemblies. In this case, do not just add them, but go into your .csproj file and make the following adjustment:

就像@dumbledad 所说的那样,当我在项目中包含在 .csproj 文件中标记为“页面”的文件时,我收到了完全相同的错误消息,导致 Visual Studio 想要编译此资源。然而,这是一个不可编译的资源(在我的例子中它是一个 XAML 文件,也可能是一个图像)Visual Studio 要求额外的程序集。在这种情况下,不要只是添加它们,而是进入您的 .csproj 文件并进行以下调整:

Search for the opening node '<Page' and verify that each instance of it actually is a page that needs to treated with the corresponding action. In my case, as you can see, a resource is marked as a Page, which VS tries to Compile:

搜索打开节点“<Page”并验证它的每个实例实际上是一个需要用相应操作处理的页面。在我的例子中,正如你所看到的,一个资源被标记为一个页面,VS 试图编译它:

<ItemGroup>
  <Page Include="sitecore\shell\ClientBin\EmptySplashScreen.xaml">
    <Generator>MSBuild:Compile</Generator>
  </Page>
</ItemGroup>

Just remove this section (or Page-node) and put the file back into the .csproj file as a regular content include. You have to do this manually, as including the file from within VS regenerates the same faulty Page-node. So I've put it back into the project file like this:

只需删除此部分(或页面节点)并将文件放回 .csproj 文件作为常规内容包含。您必须手动执行此操作,因为在 VS 中包含文件会重新生成相同的错误页面节点。所以我把它放回项目文件中,如下所示:

<Content Include="sitecore\shell\ClientBin\EmptySplashScreen.xaml" />

Et voila, your project will build again and the error message disappears without having to add those extra assembly references.

瞧,您的项目将再次构建,错误消息将消失,而无需添加那些额外的程序集引用。

回答by Ross

In Visual Studio, go to Projectmenu > Add Reference> .NETtab, select WindowsBase, PresentationCoreand PresentationFrameworkin the list and press OK. Then try again.

在 Visual Studio 中,转到Project菜单 > Add Reference>.NET选项卡,选择WindowsBasePresentationCore然后PresentationFramework在列表中按OK。然后再试一次。

回答by Reed Copsey

If you're trying to use WPF, you need to add a reference to the listed assemblies in your project references.

如果您尝试使用 WPF,则需要在项目引用中添加对列出的程序集的引用。

Open your project, and choose "Project->Add Reference...". Add the listed assemblies as references in order to use the WPF types.

打开您的项目,然后选择“项目->添加引用...”。添加列出的程序集作为引用以使用 WPF 类型。