日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

程序集、应用程序配置及App.config和YourSoft.exe.config .

發(fā)布時(shí)間:2023/11/29 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 程序集、应用程序配置及App.config和YourSoft.exe.config . 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自:http://www.cnblogs.com/luminji/archive/2010/10/21/1857339.html

  • 什么是程序集
  • 程序集標(biāo)識(shí)屬性
  • 強(qiáng)名稱的程序集
  • 強(qiáng)名稱工作原理
  • 配置文件
  • 使用 DEVPATH 查找程序集
  • 指定要使用的運(yùn)行庫(kù)版本
  • Appconfig和YourSoftexeconfig
  • 本章概要:

    1:什么是程序集

    2:程序集標(biāo)識(shí)屬性

    3:強(qiáng)名稱的程序集

    3.1:強(qiáng)名稱工作原理

    4:配置文件

    5:使用 DEVPATH 查找程序集

    6:指定要使用的運(yùn)行庫(kù)版本

    7:App.config和YourSoft.exe.config

    ?

    1:什么是程序集

    ???? 程序集是 .NET Framework 應(yīng)用程序的構(gòu)造塊;程序集構(gòu)成了部署、版本控制、重復(fù)使用、激活范圍控制和安全權(quán)限的基本單元。程序集是為協(xié)同工作而生成的類型和資源的集合,這些類型和資源構(gòu)成了一個(gè)邏輯功能單元。程序集向公共語言運(yùn)行庫(kù)提供了解類型實(shí)現(xiàn)所需要的信息。

    ???? 程序集屬性是提供程序集相關(guān)信息的值。屬性分為以下幾組信息:

    • 程序集標(biāo)識(shí)屬性。

    • 信息性屬性。

    • 程序集清單屬性。

    • 強(qiáng)名稱屬性。

    2:程序集標(biāo)識(shí)屬性

    ???? 三種屬性與強(qiáng)名稱(如果適用)一起決定程序集的標(biāo)識(shí):名稱、版本和區(qū)域性。這些屬性構(gòu)成程序集的完整名稱,并且在代碼中引用程序集時(shí)需要這些屬性。您可以使用屬性來設(shè)置程序集的版本和區(qū)域性。編譯器或程序集鏈接器 (Al.exe) 根據(jù)包含程序集清單的文件在創(chuàng)建程序集時(shí)設(shè)置名稱值。??

    ???? 有關(guān)程序集屬性的更多信息,參看http://msdn.microsoft.com/zh-cn/library/4w8c1y2s(VS.80).aspx

    ?

    3:強(qiáng)名稱的程序集

    ???? 強(qiáng)名稱是由程序集的標(biāo)識(shí)加上公鑰和數(shù)字簽名組成的,其中,程序集的標(biāo)識(shí)包括簡(jiǎn)單文本名稱、版本號(hào)和區(qū)域性信息(如果提供的話)。它使用對(duì)應(yīng)的私鑰從程序集文件中生成。(程序集文件包含程序集清單,其中包含組成程序集的所有文件的名稱和哈希。)

    ???? 具有強(qiáng)名稱的程序集只能使用其他具有強(qiáng)名稱的程序集的類型。否則將會(huì)危及到該具有強(qiáng)名稱的程序集的安全。

    ?

    3.1:強(qiáng)名稱工作原理

    簽名機(jī)制
    1. 用SN.exe 生成一個(gè)key文件, 這個(gè)key文件包括一個(gè)public key 和一個(gè)private key.
    2. 用這個(gè)key文件簽名assembly時(shí), 編譯器將用private key簽名程序集, 并將public key嵌入manifest中
    3. 編譯器哈希manifest中所有的assembly內(nèi)容, 并將此哈希值各自assembly的FileDef Talbe中.
    4. 當(dāng)如上3步處理后, 編譯器將哈希PE文件的整個(gè)內(nèi)容(除authenticode signature, 強(qiáng)名稱數(shù)據(jù), PE頭), 然后將此哈希值用private key簽名. 得到RSA數(shù)字簽名.
    5. 將此數(shù)字簽名嵌入到PE文件的CLR頭

    防修改機(jī)制
    1. 當(dāng)簽名后的assembly安裝到GAC, 系統(tǒng)會(huì)哈希PE文件(同簽名), 得到哈希值
    2. 系統(tǒng)讀取PE文件中CLR頭中的RSA簽名, 并用public key(包含在manifest中)解密
    3. 比較第1步得到的哈希值和第2步得到解密值是否一致, 從而判斷其是否被修改.

    ?

    4:配置文件

    ???? 配置文件是可以按需要更改的 XML 文件。開發(fā)人員可以使用配置文件來更改設(shè)置,而不必重編譯應(yīng)用程序。管理員可以使用配置文件來設(shè)置策略,以便影響應(yīng)用程序在計(jì)算機(jī)上運(yùn)行的方式。

    ???? 配置文件更多內(nèi)容查看http://msdn.microsoft.com/zh-cn/library/1xtk877y(VS.90).aspx。

    ?

    5:使用 DEVPATH 查找程序集

    ???? 開發(fā)人員可能想確保他們正在生成的共享程序集能與多個(gè)應(yīng)用程序一起正常使用。在開發(fā)周期內(nèi)開發(fā)人員不用頻繁地將程序集放在全局程序集緩存中,他們可以創(chuàng)建 DEVPATH 環(huán)境變量,讓該變量指向程序集的生成輸出目錄。

    ???? 例如,假設(shè)您正在生成名為 MySharedAssembly 的共享程序集,且輸出目錄是 C:/MySharedAssembly/Debug??梢詫?C:/MySharedAssembly/Debug 置于 DEVPATH 變量中。然后必須在計(jì)算機(jī)配置文件中指定 <developmentMode> 元素。該元素告訴公共語言運(yùn)行庫(kù)使用 DEVPATH 來查找程序集。

    ???? 共享程序集必須能夠由運(yùn)行庫(kù)發(fā)現(xiàn)。 若要指定用于解析程序集引用的私有目錄,請(qǐng)?jiān)谂渲梦募惺褂?<codeBase> 元素<probing> 元素,如 指定程序集的位置 中所述。 還可以將程序集放在應(yīng)用程序目錄的子目錄中。有關(guān)更多信息,請(qǐng)參見運(yùn)行庫(kù)如何定位程序集。

    ???? 下面的示例說明如何使運(yùn)行庫(kù)在由 DEVPATH 環(huán)境變量所指定的目錄中搜索程序集。

    <configuration><runtime><developmentMode developerInstallation="true"/></runtime> </configuration>

    ?

    6:指定要使用的運(yùn)行庫(kù)版本

    <?xml version ="1.0"?> <configuration><startup><supportedRuntime version="v1.1.4322" /> </startup> </configuration>

    ?

    7:App.config和YourSoft.exe.config

    ???? 為了更加快速的使用配置信息而不自己寫代碼實(shí)現(xiàn)讀寫,我們?cè)趧?chuàng)建應(yīng)用程序的時(shí)候應(yīng)該使用App.config。創(chuàng)建完畢后,我們發(fā)現(xiàn)App.config的屬性是:

    ???? 以上是創(chuàng)建App.config后的默認(rèn)設(shè)置,不要修改這些屬性,編譯你的解決方案,會(huì)在輸出目錄中發(fā)現(xiàn)生成了一個(gè)YourSoft.exe.config(假設(shè)你的應(yīng)用程序名為YourSoft.exe)。下面有幾點(diǎn)需要說明:

    ???? 1:YourSoft.exe.config其實(shí)對(duì)應(yīng)的就是你解決方案中的App.config。注意,千萬不要以為在輸出目錄中它也會(huì)以App.config存在。

    ???? 2:如果“復(fù)制到輸出目錄”屬性你設(shè)置的是“復(fù)制”或者“較新則復(fù)制”,則App.config會(huì)被復(fù)制到輸出目錄。千萬不要以為在輸出目錄中的App.config對(duì)應(yīng)用程序會(huì)有任何意義。運(yùn)行時(shí)默認(rèn)還是會(huì)去讀YourSoft.exe.config。

    ???? 3:輸出目錄中YourSoft.exe.config的值不會(huì)自動(dòng)保持和你解決方案中的App.config內(nèi)容一致。你需要手動(dòng)去設(shè)置YourSoft.exe.config中的值。


    練習(xí):

    1.You are creating a strong-named assembly named Asse? mbly1 that will be used in multiple applications.

    Assembly1 will be rebuilt frequently during the development cycle. You need to ensure that each time the?
    assembly is rebuilt it works correctly with each application that uses it. You need to configure the computer on
    which you develop Assembly1 such that each application uses the latest bu? ild of Assembly1. Which two actions
    should you perform? (Each correct answer presents part of the solution. Choose two.)
    A. Create a DEVPATH environment variable that points to the build output directory for the strong-named???????
    assembly.
    B. Add the following XML element to the machine configuration filE.??????????
    <developmentMode developerInstallation="true"/>

    C. Add the following XML element to the machine configuration filE.?????????
    <dependentAssembly>????
    <assemblyIdentity name="Assembly1" publicKeyToken="32ab4ba45e0a69a1" language="en-US"?
    version="*.*.*.*" />
    <publisherPolicy apply="no" />????
    </dependentAssembly>
    D.? Add the following XML element to the configuration file of each application that uses the strong-named???????
    assembly:??
    <supportedRuntime version="*.*.*.*" />?
    E. Add the following XML element to the configuration file of each application that uses the strong-named???
    assembly:????
    <dependentAssembly>?????
    <assemblyIdentity name="Assembly1" publicKeyToken="32ab4ba45e0a69a1" language="en-US"?
    version="*.*.*.*" />???????
    <bindingRedirect newVersion="*.*.*.*"/>????
    </dependentAssembly>
    Answer: A, B

    ?

    ?

    2.Your company uses an application named Application1 that was compiled by using the .NET Framework
    version 1.0. The application currently runs on a shared computer on which the .NET Framework versions 1.0 and?????
    1.1 are installed.???? You need to move the application to a new computer on which the .NET Framework versions?
    1.1 and 2.0 are installed. The application is compatible with the .NET Framework 1.1, but it is incompatible with???
    the .NET Framework 2.0. You need to ensure that the application will use the .NET? Framework version 1.1 on the?
    new computer. What should you do????

    A.? Add the following XML element to the application configuration file.???????
    <configuration>?????
    <startup>???????
    <supportedRuntime version="1.1.4322" />??????
    <startup>???
    </configuration>

    B. Add the following XML element to the application configuration file.???????
    <configuration>?????
    <runtime>???????
    <assemblyBinding? xmlns="urn:schemas-microsoft-com:asm.v1">?????????
    <dependentAssembly>?????????????
    <assemblyIdentity name="Application1"?
    publicKeyToken="32ab4ba45e0a69a1"? culture="neutral" />?????????????
    <bindingRedirect oldVersion="1.0.3075.0" newVersion="1.1.4322.0"/>???????????
    </dependentAssembly>??????
    </assemblyBinding>???
    </runtime>??
    </configuration>
    C. Add the following XML element to the machine configuration file.??????????
    <configuration>?????
    <startup>???????
    <requiredRuntime version="1.1.4322" />???????
    <startup>???
    </configuration>

    D.? Add the following XML element to the machine configuration file.??????????
    <configuration>?????
    <runtime>???????
    <assemblyBinding? xmlns="urn:schemas-microsoft-com:asm.v1">???
    <dependentAssembly>?????????????
    <assemblyIdentity name="Application1"?
    publicKeyToken="32ab4ba45e0a69a1"? culture="neutral" />?????????????

    <bindingRedirect oldVersion="1.0.3075.0" newVersion="1.1.4322.0"/>???????????
    </dependentAssembly>??????
    </assemblyBinding>???
    </runtime>??
    </configuration>
    Answer: A

    ?

    總結(jié)

    以上是生活随笔為你收集整理的程序集、应用程序配置及App.config和YourSoft.exe.config .的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。