Chapter3~Assembly控制管理

來源:互聯網
上載者:User

使用config管理Assembly。

以下是例子

<?xml version="1.0"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="AuxFiles;bin\subdir" />
    <dependentAssembly>
      <assemblyIdentity name="MyType"
        publicKeyToken="32ab4ba45e0a69a1" culture="neutral"/>
      <bindingRedirect
        oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      <codeBase version="2.0.0.0"
        href="http://www.MyType.com/MyType.dll" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="TypeLib"
      publicKeyToken="1f2e74e897abbcfe" culture="neutral"/>
    <bindingRedirect
      oldVersion="3.0.0.0-3.5.0.0" newVersion="4.0.0.0" />
    <publisherPolicy apply="no" />
    </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

對應節點含義為: 

probing element

  尋找弱命名Assembly在AuxFiles;bin\subdir下。

dependentAssembly, assemblyIdentity, and bindingRedirect elements

    當尋找版本為1.0.0.0 public key為32ab4ba45e0a69a1,名為MyType的Assembly的時候,替換為版本2.0的Assembly。

codeBase element

  指定版本為2.0的MyType.dll的位置

 

Public Policy

當你很小範圍的修改了以前的Assembly,如對前面的版本修正了一些Bug,此時你想讓客戶的程式很快接受你的變化。

前面已經描述了我們可以修改程式config或者machine config,但是這有時候太麻煩。

我們這時候就可以用Public Policy來適應這種變化。

首先,建立一個獨立的config檔案,此處命名為MyType.config

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="MyType"
      publicKeyToken="32ab4ba45e0a69a1" culture="neutral"/>
    <bindingRedirect
      oldVersion="1.0.0.0" newVersion="2.0.0.0" />
    <codeBase version="2.0.0.0"
      href="http://www.Mytype.com/MyType.dll/" >
    </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

 

然後,開啟AL建立Policy

AL.exe /out:Policy.1.0.MyType.dll
    /version:1.0.0.0
    /keyfile:MyKey.snk
    /linkresource:MyType.config

 

/out  此處命名很重要!指定輸出檔案名為Policy.1.0.JeffTypes.dll。Policy告訴CLR檔案裡包含Policy資訊。1.0表示該Policy對應處理的Assembly版本。MyType表示對應的Assembly名。

/version 標識此Policy版本。

/keyfile Assembly發布對應的Key。

/linksource 對應剛才建立的config檔案名稱。

 

發布的時候連同新的dll將此Policy也帶上即可,而不需修改config。

 

值得注意的是使用Policy另外的好處是,當新版本出現問題想放棄時,可以直接通過config設定。

看到一開始的配置有<publisherPolicy apply="no" />,這裡就表示屏蔽掉Policy

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.