什麼是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的重定向。