wpf 无法加载文件或程序集 Windows.winmd'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32783102/
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-13 13:26:35  来源:igfitidea点击:

Could not load file or assembly Windows.winmd'

c#.netwpfwindows-runtime

提问by eeadev

My WPF Desktop app is using WinRT classes as well.

我的 WPF 桌面应用程序也在使用 WinRT 类。

In order to do that I follow this tutorial https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications.

为了做到这一点,我遵循本教程 https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications

Fine, it works.

很好,它有效。

Now when I try to generate the msi file (I tried both with using Microsoft Installer and ClickOnce), I am getting this error:

现在,当我尝试生成 msi 文件时(我尝试使用 Microsoft Installer 和 ClickOnce),出现此错误:

Problem generating manifest. Could not load file or assembly 'C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd' or one of its dependencies. Attempt to load a program with an incorrect format.

生成清单时出现问题。无法加载文件或程序集“C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd”或其依赖项之一。尝试加载格式不正确的程序。

I already tried with disabling the ClickOnce as suggested here, with cleaning the project and with deleting ASP.NET temporary of the different NET framework.

我已经尝试按照此处的建议禁用 ClickOnce ,清理项目并删除不同 NET 框架的 ASP.NET 临时文件。

This is my startup tag in my app.config

这是我在 app.config 中的启动标签

I am using VS2015 and C# How can I fix it and generate my msi?

我正在使用 VS2015 和 C# 如何修复它并生成我的 msi?

PS: I have no problem in generating another msi with a simple WPF desktop app.

PS:我用一个简单的 WPF 桌面应用程序生成另一个 msi 没有问题。

回答by Hans Passant

Yes, the Windows.winmd file you added as a reference is an obstacle to getting the project deployed. The tools you use get confused about its content, it looksjust like a .NET assembly. But it is not, the .winmd file format is an extension of the COM type library format of old. For WinRT, they used the metadata format of .NET to get past the restrictions of the TLB file format.

是的,您作为参考添加的 Windows.winmd 文件是部署项目的障碍。您使用的工具对其内容感到困惑,它看起来就像一个 .NET 程序集。但事实并非如此,.winmd 文件格式是旧的 COM 类型库格式的扩展。对于 WinRT,他们使用 .NET 的元数据格式来突破 TLB 文件格式的限制。

That was a pretty good idea, many .NET tools can use the metadata as-is. Like compilers and disassemblers, they didn't have to put all that infrastructure into place. But it strictly plays the role of a reference assembly, only the compiler uses its content and it should never be deployed. Right now you don't like that good idea too much :)

这是一个很好的主意,许多 .NET 工具可以按原样使用元数据。像编译器和反汇编器一样,他们不必将所有这些基础设施放到位。但它严格地扮演了一个引用程序集的角色,只有编译器使用它的内容并且永远不应该部署它。现在你不太喜欢这个好主意:)

It is however very easy to fix for a ClickOnce deployment. Use Project > Properties > Publish tab > Application Files button. Change the "Publish Status" selection for Windows.winmd to "Exclude". Sample project screen-shot:

但是,修复 ClickOnce 部署非常容易。使用项目 > 属性 > 发布选项卡 > 应用程序文件按钮。将 Windows.winmd 的“发布状态”选择更改为“排除”。示例项目屏幕截图:

enter image description here

在此处输入图片说明



It isn't very clear what you mean by "Microsoft Installer", I'll assume you talk about a Setup Project. Although removed from Visual Studio due to chronic problems, it is still available in the gallery.

“Microsoft 安装程序”的含义不是很清楚,我假设您谈论的是安装项目。尽管由于长期问题已从 Visual Studio 中删除,但它仍可在库中使用。

That's a harder nut to crack, you'd normally use the Add > Project Output context menu entry to let it figure out the dependencies. That doesn't work anymore, it dies with miserable non-descript error message:

这是一个更难破解的问题,您通常会使用“添加”>“项目输出”上下文菜单条目来确定依赖项。这不再起作用,它以悲惨的非描述性错误消息死亡:

ERROR: An error occurred while validating. HRESULT = '80070057'

错误:验证时出错。HRESULT = '80070057'

The error code means "Invalid parameter", that doesn't help narrow down the problem. But you can safely assume that it dies on trying to resolve the Windows.winmd reference in the .exe assembly.

错误代码的意思是“参数无效”,这无助于缩小问题的范围。但是您可以安全地假设它在尝试解析 .exe 程序集中的 Windows.winmd 引用时死亡。

The workaround is to notlet it auto-detect the dependencies but pick them yourself. From the editor screen titled "File System on Target machine", select the Application Folder. Right-click "Primary output from ..." and select Delete.

解决方法是不要让它自动检测依赖项,而是自己选择它们。从标题为“目标机器上的文件系统”的编辑器屏幕中,选择应用程序文件夹。右键单击“来自...的主要输出”并选择删除。

Right-click Application Folder > Add > File and pick the project's .exe file from the bin\Release folder. Repeat for other files, you can use the file listing you got in the ClickOnce application files listing as a guide.

右键单击应用程序文件夹 > 添加 > 文件,然后从 bin\Release 文件夹中选择项目的 .exe 文件。对其他文件重复此操作,您可以使用在 ClickOnce 应用程序文件列表中获得的文件列表作为指南。

Build the project, you now get:

构建项目,你现在得到:

WARNING: Unable to find dependency 'WINDOWS' (Signature='(null)' Version='255.255.255.255') of assembly 'WindowsFormsApplication144.exe'

警告:无法找到程序集 'WindowsFormsApplication144.exe' 的依赖项 'WINDOWS' (Signature='(null)' Version='255.255.255.255')

Which is entirely benign, we don't want it to find it, the Setup.exe program works fine.

这是完全良性的,我们不希望它找到它,Setup.exe 程序运行良好。