共用方式為


SharePoint 工具擴充功能的程式撰寫模型概觀

更新:2010 年 5 月

您在 Visual Studio 2010 中建立 SharePoint 工具的擴充功能時,會從實作一個或多個由 SharePoint 工具公開的擴充性介面開始。 在大多數情況下,您也會使用 SharePoint 工具所提供的其他類型來實作擴充功能中的功能。 在大多數情況下,您也可以使用 Visual Studio 和 SharePoint 所提供的其他物件模型中的類型。 您必須了解每個這些物件模型的用途,並知道如何將這些物件模型搭配使用,才能建立 SharePoint 工具的擴充功能。

實作擴充性介面以擴充 SharePoint 工具

Visual Studio 使用 .NET Framework 4 中的 Managed Extensibility Framework (MEF),為 SharePoint 工具提供擴充性模型。 MEF 是 API (在 System.ComponentModel.Composition 組件中實作),可讓應用程式公開擴充點,並在執行階段探索及載入擴充功能。 如需 MEF 的詳細資訊,請參閱 Managed Extensibility Framework 概觀

若要擴充 SharePoint 工具,請實作一個或多個由 Visual Studio 公開的擴充性介面。 您也必須視需要將 System.ComponentModel.Composition.ExportAttribute 和其他 SharePoint 工具特定的屬性套用至介面實作。 下表列出可用來實作以擴充 SharePoint 工具的介面清單。

介面

描述

ISharePointProjectItemTypeProvider

實作這個介面以定義新的 SharePoint 專案項目類型。 如需範例,請參閱 HOW TO:定義 SharePoint 專案項目類型

ISharePointProjectItemTypeExtension

實作這個介面以擴充已經安裝在 Visual Studio 中的 SharePoint 專案項目類型。 如需範例,請參閱 HOW TO:建立 SharePoint 專案項目擴充功能

ISharePointProjectExtension

實作這個介面以擴充 SharePoint 專案。 如需範例,請參閱 HOW TO:建立 SharePoint 專案擴充功能

IDeploymentStep

實作這個介面以定義新的部署步驟,可以在部署或撤銷 SharePoint 專案項目時執行。 如需範例,請參閱 逐步解說:建立 SharePoint 專案的自訂部署步驟

IExplorerNodeTypeExtension

實作這個介面以擴充 [伺服器總管] 視窗中 [SharePoint 連接] 節點底下的現有節點。 如需範例,請參閱 HOW TO:在伺服器總管中擴充 SharePoint 節點

IExplorerNodeTypeProvider

實作這個介面以定義 [伺服器總管] 視窗中 [SharePoint 連接] 節點底下的新節點類型。 如需範例,請參閱 HOW TO:在伺服器總管中擴充 SharePoint 節點

IFeatureValidationRule

實作這個介面以定義自訂功能驗證規則。 如需範例,請參閱 HOW TO:建立 SharePoint 方案的自訂功能和封裝驗證規則

IPackageValidationRule

實作這個介面以定義自訂封裝驗證規則。 如需範例,請參閱 HOW TO:建立 SharePoint 方案的自訂功能和封裝驗證規則

實作 SharePoint 工具的擴充功能後,您必須部署 Visual Studio 擴充功能 (VSIX) 套件中的擴充功能組件,才能讓 Visual Studio 探索及載入擴充功能。 如需詳細資訊,請參閱部署 Visual Studio 中 SharePoint 工具的擴充功能

了解 SharePoint 工具擴充功能中使用的物件模型

建立 SharePoint 工具的擴充功能時可以使用幾種物件模型:

  • 「SharePoint 工具物件模型」(SharePoint Tools Object Model)。 這種物件模型提供可用來實作以建立 SharePoint 工具擴充功能和其他相關類型的擴充性介面。

  • 「Visual Studio Automation 和整合物件模型」(Visual Studio Automation and Integration Object Model)。 這些物件模型可用來存取 SharePoint 工具物件模型範圍之外的 Visual Studio 功能。

    注意事項注意事項

    您可以使用 SharePoint 專案服務將 SharePoint 工具物件模型中的某些物件,轉換成 Visual Studio Automation 和整合物件模型中的物件,反之亦然。 如需詳細資訊,請參閱在 SharePoint 專案系統類型與其他 Visual Studio 專案類型之間轉換

  • 「SharePoint 伺服器和用戶端物件模型」(SharePoint Server and Client Object Model)。 這些物件模型可用來在 SharePoint 工具擴充功能的內容中修改 SharePoint 網站或從 SharePoint 網站擷取資料。

SharePoint 工具物件模型

每個 SharePoint 工具擴充功能都會使用 SharePoint 工具物件模型中的類型,定義擴充功能的核心行為和功能。 下表說明此物件模型中包含的命名空間。

組件

命名空間

描述

Microsoft.VisualStudio.SharePoint.dll

Microsoft.VisualStudio.SharePoint

包含用來擴充及自動化 SharePoint 專案系統的類型。 例如,您可以擴充內建的 SharePoint 專案和專案項目,或是建立自己的專案項目。 如需詳細資訊,請參閱擴充 SharePoint 專案系統

Microsoft.VisualStudio.SharePoint.Deployment

包含用來擴充 SharePoint 專案之部署程序的類型,例如建立您自己的部署步驟和組態。 如需詳細資訊,請參閱擴充 SharePoint 封裝和部署

Microsoft.VisualStudio.SharePoint.Explorer

包含用來擴充 [伺服器總管] 視窗中 [SharePoint 連接] 節點底下的節點,或定義新的節點類型。 如需詳細資訊,請參閱在伺服器總管中擴充 SharePoint 連線節點

Microsoft.VisualStudio.SharePoint.Features

包含用來存取 SharePoint 專案中功能定義的類型。

Microsoft.VisualStudio.SharePoint.Packages

包含用來存取 SharePoint 方案中封裝定義的類型。

Microsoft.VisualStudio.SharePoint.Validation

包含用來自訂 SharePoint 專案的功能和封裝驗證行為的類型。 如需詳細資訊,請參閱 HOW TO:建立 SharePoint 方案的自訂功能和封裝驗證規則

Microsoft.VisualStudio.SharePoint.Commands.dll

Microsoft.VisualStudio.SharePoint.Commands

包含可用來建立自訂「SharePoint 命令」(SharePoint Command) 的型別。 SharePoint 命令是從 SharePoint 工具擴充呼叫 SharePoint 伺服器物件模型的方法。 如需詳細資訊,請參閱呼叫 SharePoint 物件模型

Microsoft.VisualStudio.SharePoint.Explorer.Extensions.dll

Microsoft.VisualStudio.SharePoint.Explorer.Extensions

包含可用來取得有關內建 [伺服器總管] 節點的相關資訊,這些節點表示 SharePoint 網站上的個別元件,例如表示清單、欄位或內容型別的節點。 如需詳細資訊,請參閱在伺服器總管中擴充 SharePoint 連線節點

Visual Studio Automation 物件模型

Visual Studio Automation 物件模型提供可用來自動化 Visual Studio 專案和 IDE 的 API。 使用 Visual Studio 物件模型可執行非 SharePoint 專案專屬的專案相關工作,或是執行 Visual Studio 中其他一般自動化工作。 通常此物件模型是在 Visual Studio 增益集和巨集中使用,但是也可以在 SharePoint 工具擴充功能中使用。

Visual Studio Automation 物件模型的主要部分是在 EnvDTE.dll 組件中定義。 Visual Studio 2005、Visual Studio 2008 和 Visual Studio 2010 中加入的其他功能是由 EnvDTE80.dll、EnvDTE90.dll 和 EnvDTE100.dll 組件提供。 這些組件包含在 Visual Studio 2010 中。

如需 Automation 物件模型的詳細資訊,請參閱擴充 Visual Studio 環境Automation 與擴充性參考

Visual Studio 整合物件模型

整合物件模型提供許多 API,可透過建立 VSPackage 的方式將功能加入至 Visual Studio。 VSPackage 是模組,可透過提供自訂功能如工具視窗、編輯器、設計工具、服務和專案的方式,擴充 Visual Studio IDE。

如果要加入將搭配內建 SharePoint 工具使用的 Visual Studio 新功能,則可以使用整合物件模型。 例如,如果您為 SharePoint 網站建立代表自訂動作的自訂 SharePoint 專案項目,則也可以建立實作自訂動作之設計工具的 VSPackage。 您可以透過將內容功能表項目加入至代表 [方案總管] 中自訂動作之專案項目的方式,讓設計工具與自訂動作產生關聯。 開發人員以滑鼠右鍵按一下自訂動作專案項目,就可以開啟您的設計工具。

此物件模型是在 Visual Studio SDK 內含的組件集中定義。 此物件模型中的一些主要組件包括 Microsoft.VisualStudio.Shell.dll、Microsoft.VisualStudio.Shell.Interop.dll 和 Microsoft.VisualStudio.OLE.Interop.dll。

如需整合物件模型的詳細資訊,請參閱 Visual Studio Development Environment ModelVisual Studio SDK Reference

SharePoint 物件模型

SharePoint 工具擴充功能可以使用 SharePoint API 修改 SharePoint 網站或從 SharePoint 網站擷取資料。 Microsoft SharePoint Foundation 2010 和 Microsoft SharePoint Server 2010 提供兩種不同的物件模型:伺服器物件模型和用戶端物件模型。

您可以在 SharePoint 工具擴充功能的任一種物件模型中使用 API,但是每個物件模型在 SharePoint 工具擴充功能環境下都有優缺點。 如需詳細資訊,請參閱呼叫 SharePoint 物件模型

物件模型

描述

伺服器物件模型

伺服器物件模型可讓您存取 Microsoft SharePoint Foundation 2010 和 Microsoft SharePoint Server 2010 透過程式設計的方式提供的所有功能。 此物件模型的設計是提供 SharePoint 伺服器上執行的 SharePoint 方案使用。 此物件模型大部分是在 Microsoft.SharePoint.dll 組件中定義。 如需伺服器物件模型的詳細資訊,請參閱使用 SharePoint Foundation 伺服器端物件模型 (英文)。

用戶端物件模型

用戶端物件模型是伺服器物件模型的子集,可用來與遠端用戶端或伺服器上的 SharePoint 資料互通。 它的設計在於盡可能減少執行一般工作時必須執行的來回行程次數。 用戶端物件模型大部分是在 Microsoft.SharePoint.Client.dll 和 Microsoft.SharePoint.Client.Runtime.dll 組件中定義。 如需用戶端物件模型的詳細資訊,請參閱 Managed 用戶端物件模型 (英文)。

請參閱

概念

呼叫 SharePoint 物件模型

Visual Studio Development Environment Model

使用 SharePoint 專案服務

其他資源

擴充 Visual Studio 中的 SharePoint 工具

變更記錄

日期

記錄

原因

2010 年 5 月

新增 SharePoint 工具物件模型所公開之 MEF 介面的詳細資訊。

資訊加強。