您的位置:首页 > Web前端

Madifest文件详解

2017-02-06 20:54 120 查看
Madifest是个XML的描述文件,对于每个DLL有DLL的Manifest文件,对于每个应用程序Application也有自己的Manifest。对于应用程序而言,Manifest可以是一个和exe文件同一目录下的.manifest文件,也可以是作为一个资源嵌入在exe文件内部的(Embed Manifest)。

XP以前版本的windows,会像以前那样执行这个exe文件,寻找相应的dll,没有分别Manifest只是个多余的文件或资源,dll文件会直接到system32的目录下查找,并且调用。这样,如果公共DLL升级,将会导致之前安装的应用程序不能使用,这就是“DLL Hell”的来源。为了解决这个问题,.NET开发提出了side-by-by的开发方法,来避免这个问题。主要方法,就是通过Manifest文件来查找相应的DLL。XP及以后的系统都集成了这样一种查找DLL的方法。

编辑


提取Manifest

默认Manifest文件都是内嵌在exe/dll中的,如果需要查看。VS提供mt.exe工具来从exe/dll中提取Manifest文件。
mt.exe -inputresource:d:\test.exe -out:d:\test.manifest


编辑


的Manifest文件有关设置

我们编译MFC工程时,会在stdafx.h文件里看到下列代码。
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif


如果是非unicode版本,则生成的界面是Win98风格,如果是unicdoe版本,则是当前操作系统的风格。 

Linker→Manifest
file→Generate Manifest→yes 即会生成EXE/DLL所用的Manifest文件。
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.MFC' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*' />
</dependentAssembly>
</dependency>
</assembly>


如果没有设置上面的控件风格,则生成的Manifest不会包括contrls.
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.MFC' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
</assembly>


所有的exe/dllFT都必须要有Manifest。如果Linker→Manifest file→Generate Manifest→No,则在必须Manifest Tool→Additinal Manifest Files中指定相应的Manifest文件。 Manifest Tool→Embed Manifest→Yes。一般都是将Manifest文件嵌套在程序中。也可以不嵌套在程序中,像MFCxx.dll, MSVCRxx.Dll,MSVCPxx.dll都是没有将Manifest嵌套在程序中的。所以当使用它们时必须与其Manifest文件一起使用。

编辑


EXE调用DLL的过程

以下针对链接MFCxx.dll, MSVCPXX.DLL, MSVCRxx.dll的程序。 

系统启动exe时,会先检查其Manifest文件(如果没有查找到当前EXE中有Manifest,则会报“程序配置不正确的”的错误提示),查找系统中是否有注册相应的Dll组件。如果有,则会去c:\windows\winsxs\Manifest文件夹根据相应的调用策略及Manifest文件,然后再根据Manifest中的内容去c:\windows\winsxs同名文件夹中查找到关的DLL。 

如果没有查找到相应的DLL,则会到当前目录来查找Microsoft.VC80.CRT.manifest和Microsoft.VC80.MFC.manifest。 

如果没有查找到当前EXE中有Manifest,则会报“程序配置不正确的”的错误提示。查到之后,就会去找相应的DLL。然后执行程序。

编辑


相关DLL介绍

选择Use MFC in share DLL会用到MFCxx.DLL. MFC80.dll, 即对应VS2005的。 MFC80U.DLL,即对应VS2005的Unicode版本。

选择MD/MDd则会用到下面的DLL。 MSVCR80.dll,即VS2005下的C RunTime库,提供基本的C函数。 MSVCP80.dll, 即VS2005年的C++函数库,如果有调用<string>之类的文件,则会使用到此DLL。

编辑


注意

1、X86、X64需要去VS工具目录
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\redist\x86
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\redist\x64


2、Manifest文件自VS2010之后,又被集成到模块当中去了,不再分开提供。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: