C# - 我需要清单文件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1815228/
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
C# - do I need manifest files?
提问by Mirek
I am curious whether I need two manifest files that are created when I publish my application. It works when I delete them. In the case they are needed, I have tried to embed (Project>Application>Embed manifest with default setting) them but they are still external.
我很好奇我是否需要在发布应用程序时创建的两个清单文件。当我删除它们时它会起作用。在需要它们的情况下,我尝试嵌入(项目>应用程序>使用默认设置嵌入清单)它们,但它们仍然是外部的。
Those are: (appname).exe.manifest
and (appname).application
.
它们是:(appname).exe.manifest
和(appname).application
。
回答by Graviton
It is needed for the purpose of
需要它的目的是
specifying the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes
指定程序集的版本要求和安全标识,以及定义程序集范围和解析对资源和类的引用所需的所有元数据
回答by Jeremy McGee
The manifest file describes how your application should run. From MSDN:
清单文件描述了您的应用程序应该如何运行。从MSDN:
Every assembly, whether static or dynamic, contains a collection of data that describes how the elements in the assembly relate to each other. The assembly manifest contains this assembly metadata. An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.
每个程序集,无论是静态的还是动态的,都包含一组数据,这些数据描述了程序集中的元素如何相互关联。程序集清单包含此程序集元数据。程序集清单包含指定程序集版本要求和安全标识所需的所有元数据,以及定义程序集范围和解析对资源和类的引用所需的所有元数据。程序集清单可以存储在带有 Microsoft 中间语言 (MSIL) 代码的 PE 文件(.exe 或 .dll)中,也可以存储在仅包含程序集清单信息的独立 PE 文件中。
So deleting them is probably the wrong thing to do, especially if you want your application to run elevated by default on Vista and beyond.
因此,删除它们可能是错误的做法,尤其是如果您希望您的应用程序在 Vista 及更高版本上默认运行提升。
Hereare details from MSDN on use of the mt tool, which is used to embed the manifest in your application.
以下是 MSDN 中有关使用 mt 工具的详细信息,该工具用于将清单嵌入到您的应用程序中。
Also note a really interesting issueconcerning the caching of the manifest in Vista and beyond that looks like a real gotcha.
还要注意一个非常有趣的问题,它涉及在 Vista 和其他版本中缓存清单,这看起来像是一个真正的问题。
回答by t0mm13b
Also, Back when VS2003 was used, and you want to make your controls look more like the XP interface, the manifest will contain the common controls with the appropriate version 6.x which is used along with your application, then the GUI gets a "nice updated look and feel of XP" instead of the old clunky windows 2000 controls. For that reason, you can have the manifest embedded as a resource so you do not have to lug around a manifest file (ok, it is a quite small file) but nonetheless, it makes the application distribution neater.
此外,在使用 VS2003 时,如果您想让您的控件看起来更像 XP 界面,清单将包含与您的应用程序一起使用的适当版本 6.x 的通用控件,然后 GUI 会得到一个“ XP 的漂亮更新外观和感觉”,而不是旧的笨重的 Windows 2000 控件。出于这个原因,您可以将清单嵌入为资源,这样您就不必拖着清单文件(好吧,它是一个非常小的文件),但尽管如此,它使应用程序分发更加整洁。
And also, there was a bug in the .NET 1.1 runtime (now fixed in 2.0+) where if a manifest is used at your application fails to update the GUI to give it more of an XP look and feel. The workaround at the time was to call Application.DoEventsbefore doing an Application.Run(new form());
而且,.NET 1.1 运行时(现已在 2.0+ 中修复)中存在一个错误,如果在您的应用程序中使用清单,则无法更新 GUI 以使其更具 XP 外观和感觉。当时的解决方法是在执行Application.Run(new form());之前调用Application.DoEvents ;
Now, with Vista and Win 7, the manifest is used to specify elevated permissions to get around the UAC thereby minimizing the chance of Vista/Win 7 having to pop up an UAC dialog box.
现在,对于 Vista 和 Win 7,清单用于指定提升的权限以绕过 UAC,从而最大限度地减少 Vista/Win 7 必须弹出 UAC 对话框的机会。