Managed Add-In Improvements
加載宏的改進(jìn)
?。ㄗg者:原文中有多處出現(xiàn)Managed,筆者認(rèn)為直譯出來反而會很繞口,忽略它也不會影響理解。)
Today we have the second of two guest posts from Patrick Smith, a program manager on the Office Programmability team.
今天,我們發(fā)表兩篇客串帖子中的第二篇,來自Patrick Smith,Office 程序開發(fā)小組的程序經(jīng)理。
Overview and Background
概述和背景
Managed code is becoming more and more pr*ent in add-ins written for Microsoft Office products. Also shipping around the same time frame as the 2007 Microsoft Office System is the next version of Visual Studio Tools for Office (VSTO). The next version of VSTO has added support for creating application level add-ins. The demand for better support of managed add-ins is clear since with Office 2003, there are a few challenges when running managed code. Among these challenges are security, resiliency, administration, and isolation. Most of these challenges are the result of add-ins based on mscoree.dll which is the loader used by the default VS.NET add-in template.
代碼在為Office成品編寫的加載宏里變得越來越流行了。Visual Studio Tools for Office (VSTO)下個版本和Office 2007大概在同一時間段上市。VSTO的下個版本增加了對在應(yīng)用軟件級創(chuàng)建加載宏的支持。自從Office 2003開始,代碼的更好支持的需求就已經(jīng)清楚了,但是,運行代碼時會有一些挑戰(zhàn)。在這些挑戰(zhàn)中有安全,恢復(fù),管理和隔離。這些挑戰(zhàn)中的大多數(shù)都是由于加載宏基于mscoree.dll而導(dǎo)致,mscoree.dll是缺省的VS.Net加載宏模板使用的加載器。
While there are workarounds to these barriers such as creating a separate unmanaged “shim” to use in place of mscoree.dll, we wanted to make this process better for the products in the 2007 Microsoft Office System. We’ve done exactly that!
有些工作區(qū)域是針對這些障礙的,例如創(chuàng)建一個單獨的“shim”來代替mscoree.dll,我們想要讓Office 2007系統(tǒng)中的這個過程變得更好一些。我們正是那樣做的!
The Improvements
As a developer, you can now design your add-in to use a new AddinLoader supplied in a new version of VSTO. This new AddinLoader helps overcome these historical challenges when running managed code in Office:
改進(jìn)
作為一名開發(fā)者,你現(xiàn)在可以使用VSTO新版本提供的AddinLoader來設(shè)計你的加載宏了。在Office里運行代碼時,新的AddinLoader幫助克服那些歷史挑戰(zhàn)。
The security model – Microsoft Office System 2003 products bases all add-in security decisions based on mscoree.dll which cannot be signed. Because of this security model, the add-in itself can be signed but the Office product would not know it because it is only looking at mscoree.dll. and since it’s only looking at mscoree.dll, no add-in can run when the Office application is set to High security. Now, if an add-in is based on the AddinLoader, the 2007 Microsoft Office System will be able to defer to the .NET security model to make the security decisions for the add-in. This is only possible by using AddinLoader.
安全模式——Office系統(tǒng)2003產(chǎn)品架構(gòu)里的所有加載宏的安全決定都是基于mscoree.dll,它是不可簽名的。正因為該安全模式,加載宏本身不可簽名,而Office產(chǎn)品也不會知道,因為它只看mscoree.dll,并且,因為只看mscoree.dll,所以當(dāng)Office應(yīng)用軟件設(shè)置安全性為高時,沒有加載宏可以運行?,F(xiàn)在,如果加載宏是基于AddinLoader的話,那么Office 2007系統(tǒng)就能夠區(qū)別.NET安全模式,為加載宏決定安全性。只有使用AddinLoader,這才是可能的。
The resiliency model – Microsoft Office System 2003 products will automatically disable add-ins that fail to load so that future problems with the add-in can be prevented, however, since the add-in is actually seen as mscoree.dll, mscoree.dll is the add-in that is disabled rather than the actual managed COM add-in that is causing a problem. This prevents any other mscoree.dll based add-ins from loading as well because the loader itself is disabled. Now the add-in is seen rather than the loader and ill-behaving add-ins can be disabled individually rather than the loader.
恢復(fù)模式——Office 2003系統(tǒng)的產(chǎn)品會自動禁用加載失敗的加載宏,因此,就可以避免該加載宏以后的問題,然而,因為該加載宏實際上是被看作mscoree.dll的,mscoree.dll是被禁用的加載宏,而不是實際上導(dǎo)致該問題的COM加載宏。這就會防止任何基于mscoree.dll的加載宏加載,因為加載器本身被禁用了?,F(xiàn)在,看的是加載宏而不是加載器,具體有錯誤行為的加載宏被禁用,而不是加載器被禁用。
Administration – When viewing the Add-Ins dialog box, mscoree.dll is seen as the add-in name rather than the actual managed COM add-in that is running within mscoree.dll. Once you are running more than one add-in, it becomes difficult to discern which one is which. Now the name of the actual add-in is displayed.
管理——當(dāng)查看加載宏對話框時,mscoree.dll就會被看作是加載宏名稱,而不是實際在mscoree.dll里運行的COM加載宏。一旦你在運行多個加載宏,就很難辨別哪個是哪個了。現(xiàn)在,顯示的是實際的加載宏的名稱了。
Runtime Isolation – mscoree.dll loads all add-ins into the default AppDomain. Therefore, with no memory isolation, add-ins can step on each other and affect objects that are shared between add-ins. The new AddinLoader will use separate AppDomains for the add-in and therefore provide isolation to that add-in.
運行時間隔離——mscoree.dll將所有加載宏加載到默認(rèn)的AppDomain。因此,沒有內(nèi)存隔離,加載宏可以相互步入,影響加載宏之間共享的對象。新的AddinLoader將給每個加載宏使用獨立的AppDomains,因此,實現(xiàn)了對該加載宏的隔離。
What’s needed
In order to take advantage of these new improvements, you will need to create your add-in using the new version of VSTO. (There is a technology preview of this version located here.
需要什么
為了利用這些新的改進(jìn),你將需要使用VSTO新版本(這里有篇對該版本的技術(shù)概述)來創(chuàng)建你的加載宏。
In addition, you’ll need to ensure the following configuration is available on the machine where the add-in is to be loaded:
Common Language Runtime 2.0 or greater
VSTO Runtime (from the new version of VSTO)
CAS policy giving the Add-in full trust
另外,你需要確保在加載宏加載的機器上有下述配置可用:
Common Language Runtime 2.0或以上版本
VSTO Runtime(來自VSTO的新版本)
CAS政策給加載宏充分信任
All of these prerequisites can be configured through the setup project for the add-in you create in VSTO.
所有這些前提條件都可以從你在VSTO里創(chuàng)建的加載宏的安裝工程里配置。