程式集清單

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

程式集清單(英語:assembly manifest)是.Net Framework中的文字檔案,包含了CLI 程式集元數據,包括程式集的組建間的依賴關係、解決資源與類的參照、版本資訊、作用域資訊、安全許可等。[1]儲存在PE檔案(.exe或.dll)用通用中間語言 (MSIL) 代碼表示。

嵌入到程式集中的程式集清單可用Windows SDK中的IL反組譯程式(ILDASM.exe)檢視。

程式集清單的內容[編輯]

下表的前四行:程式集名字、版本號、culture、強名字資訊,組成了程式集的identity。

程式集清單的內容
資訊 描述
Assembly name 一個文字字串指出程式集的名字。
Version number 主版本號、次版本號、revision號、build號。通用語言執行時使用這些版本號執行版本政策(version policy)。
Culture 該程式集支援的文化或語言的資訊。 一個帶有culture資訊的程式集自動被認為是一個satellite程式集。
Strong name information 對於一個被給定一個強名字程式集,發佈者的公鑰
程式集中所有檔案的列表 包含在程式集中的每個檔案的雜湊值與檔名。注意,組成程式集的所有檔案必須在包含了程式集清單的檔案所在的目錄中。
類型推導資訊 對於程式集輸出的類型,通用語言執行時使用該資訊把類型推導對映到包含了該類型聲明與實現的那個檔案。
被參照的程式集的資訊 當前程式集靜態參照的其他程式集的列表。每個參照包含了被依賴的程式集的名字、版本、culture、作業系統等等,以及公鑰(如果被依賴的程式集是強名字)。

.NET實現[編輯]

Manifest是一個以.manifest為字尾的XML檔案。其內部的資訊:

  • <assemblyIdentity>元素則標識着一個唯一的程式集
  • 指定了組成程式集的檔案及Windows類。

作業系統首先讀取Manifest,獲得exe檔案需要呼叫的DLL的manifest。再根據據此資訊去尋找對應的DLL。這樣就可能區別不同版本的同一個DLL檔案。

共用程式集的Manifests儲存在WINDOWS/WinSxS/Manifests目錄中。這是Windows XP以上版本作業系統提供的非寄存(多版本)並列快取(side-by-side cache)中安裝了強名字的系統庫的程式集清單。在WinSxS目錄下,每個程式集都會有一個目錄,另外,還有兩個目錄分別是Manifests和Policies,其中包含了版本的相關資訊。例如:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
	<noInheritable></noInheritable>
	<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50727.42" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
	<file name="msvcr80.dll" hash="2a0d797a8c5eac76e54e98db9682e0938c614b45" hashalg="SHA1">
		<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
			<dsig:Transforms>
				<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform>
			</dsig:Transforms>
			<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod>
			<dsig:DigestValue>phRUExlAeZ8BwmlD8VlO5udAnRE=</dsig:DigestValue>
		</asmv2:hash>
	</file>
	<file name="msvcp80.dll" hash="cc4ca55fb6aa6b7bb8577ab4b649ab77e42f8f91" hashalg="SHA1">
		<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
			<dsig:Transforms>
				<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform>
			</dsig:Transforms>
			<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod>
			<dsig:DigestValue>7AY1JqoUvK3u/6bYWbOagGgAFbc=</dsig:DigestValue>
		</asmv2:hash>
	</file>
	<file name="msvcm80.dll" hash="55e8e87bbde00d1d96cc119ccd94e0c02c9a2768" hashalg="SHA1">
		<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
			<dsig:Transforms>
				<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform>
			</dsig:Transforms>
			<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod>
			<dsig:DigestValue>hWq8zazTsMeKVxWFBa6bnv4hEOw=</dsig:DigestValue>
		</asmv2:hash>
	</file>
</assembly>

用戶:

<?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>
</assembly>

在WINDOWS/WinSxS/Policies目錄下的Policy檔案,來指出老版本到新版本的確認對映關係。解決庫升級帶來的版本相容問題。例如:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright ? 1981-2001 Microsoft Corporation -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
	<assemblyIdentity type="win32-policy" name="policy.8.0.Microsoft.VC80.CRT" version="8.0.50727.42" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"/>
	<dependency>
		<dependentAssembly>
			<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"/>
			<bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
		</dependentAssembly>
	</dependency>
</assembly>

其中<bindingRedirect>標籤便指定了所有8.0.41204.256-8.0.50608.0版本的需求,對映到8.0.50727.42這個系統中安裝的比較新的版本的庫。

參考文獻[編輯]

  1. ^ .NET 中的程序集 at MSDN. [2019-07-04]. (原始內容存檔於2019-07-04).