一分鐘明白 VS manifest 原理
什么是vs 程序的manifest文件
manifest 是VS程序用來標明所依賴的side-by-side組建,如ATL, CRT等的清單。
為什么要有manifest文件
一臺pc上,用一組建往往會有不止一個版本(c:/windows/winsxs或系統目錄下),程序在加載的時候,不知加載哪個,于是manifest文件來指明。
manifest在哪兒,如何創建。
如果用VS開發,可以Set通過porperty->configuration properties->linker->manifest file->Generate manifest To Yes來自動創建manifest來指定系統的和CRT的assembly版本。
除了這樣產生外部的manifest file,還有embedded manifest信息可以被寫到所生成的二進制文件內
Set porperty->configuration properties->manifest tool->embed manifest To Yes
對于xp及早前的windows版本,external manifest會比embed manifest有更高的優先級,但對于windows server及后的版本,相反。
為什么我的manifest明明指明
name="Microsoft.VC80.DebugCRT" version="8.0.50608.0",
但是用depends.exe工具卻發現引用的是8.00.50727.42呢?
因為在C:/WINDOWS/WinSxS/Policies下,有publisher configuration file也叫policy文件,如8.0.50727.42.policy文件對依賴做了重定向:
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC80.DebugCRT" processorArchitecture="ia64" publicKeyToken="1fc8b3b9a1e18e3b"/>
<bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
</dependentAssembly>
指明"8.0.41204.256-8.0.50608.0"都被定向到8.0.50727.42。這是assembly提供商如MS對低級版本bug的修正而提供的解決方法。除此之外,你也可以用application config文件來對本程序做assembly的重定向。如在你bin local文件夾下 yourbin.extention.config:
<configuration>
<windows>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC80.ATL" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
<bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC80.DebugCRT" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"/></assemblyIdentity>
<bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
</dependentAssembly>
</assemblyBinding>
</windows>
</configuration>
如何決定我程序manifest信息所指定的assembly版本信息?
在assembly頭文件中,assembly的版本信息被指明了。如crtassem.h中
#ifndef _CRT_ASSEMBLY_VERSION
#define _CRT_ASSEMBLY_VERSION "8.0.50608.0"
#endif
可以修改8.0.50608.0為8.0.50727.42以產生你想要的manifest信息。
若我想將我的程序發布為獨立程序集(isolated application),不去依賴目標pc的系統assembly,該怎么辦?
帶上所有依賴的assembly和相應的manifest文件(c:/windows/winsxs),注意,manifest信息要直接可以指定到所附帶的assembly DLLs,不需要依賴policy的重定向。
RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成