每個 SharePoint Feature 的定義核心,Feature.xml 中的 <Feature> 元素宣告 Feature 身分、範圍、相依組件、元素清單與屬性包。位於 12\TEMPLATE\FEATURES\FeatureName\ 目錄下。
| 屬性 | 類型 | 預設 | 說明 |
|---|---|---|---|
| ActivateOnDefault | Boolean | TRUE | 安裝/建立 Web App 時自動啟用。Site/Web 範圍不適用。 |
| AlwaysForceInstall | Boolean | FALSE | 強制重新安裝,即使已安裝。所有範圍生效。 |
| AutoActivateInCentralAdmin | Boolean | FALSE | 管理中心/站台集/Web App 預設啟用。Farm 範圍不適用。 |
| Creator | Text | - | 作者資訊。 |
| DefaultResourceFile | Text | - | 指定共用資源檔(預設找 Resources\Resources.<Culture>.resx)。 |
| Description | String | - | 功能描述。 |
| Hidden | Boolean | FALSE | 隱藏不在 UI 顯示。 |
| Id | Text (GUID) | 必填 | Feature 唯一識別碼。 |
| ImageUrl | Text | - | UI 顯示圖片相對路徑。 |
| ImageUrlAltText | Text | - | 圖片替代文字。 |
| ReceiverAssembly | Text | - | 事件接收器組件強名稱(配合 ReceiverClass)。 |
| ReceiverClass | Text | - | 事件處理類別完整名稱。 |
| RequireResources | Boolean | - | 驗證特定語言資源檔存在才顯示於 UI(僅影響 UI 啟用)。 |
| Scope | Text | 必填 | 範圍:Farm、WebApplication、Site、Web。 |
| SolutionId | Text | - | 所屬 Solution ID。 |
| Title | Text | - | 顯示標題(≤255 字元)。 |
| Version | Text | - | System.Version 格式(最多四段數字)。 |
宣告本 Feature 啟用所需的其他 Feature:
<ActivationDependencies>
<ActivationDependency FeatureId="11111111-1111-1111-1111-111111111111" />
</ActivationDependencies>
<ElementManifest Location="..." />:包含 Feature 元素定義的 XML 檔(如 ListTemplate、ContentType、Field 定義)。<ElementFile Location="..." />:支援性檔案(如 .aspx、.js、.css、圖片),不解析為元素定義,僅部署至 12 Hive。鍵值對集合,啟用時可由事件接收器讀取:
<Properties>
<Property Key="Color" Value="Blue" />
<Property Key="Shape" Value="Triangle" />
</Properties>
<Feature
Id="11111111-1111-1111-1111-11111111111"
Title="Location Services"
Description="This Feature contains lists and parts that let you link location data to your customer lists."
Scope="Web">
<ActivationDependencies>
<ActivationDependency FeatureId="11111111-1111-1111-1111-111111111111" />
</ActivationDependencies>
<ElementManifests>
<ElementManifest Location="Location\LocationPart.xml" />
<ElementManifest Location="CustomerLocation\CustomerLocationList.xml" />
<ElementFile Location="test.aspx" />
</ElementManifests>
<Properties>
<Property Key="Color" Value="Blue" />
<Property Key="Shape" Value="Triangle" />
</Properties>
</Feature>
RequireResources 僅影響 UI 顯示,**不阻擋 stsadm 命令列或物件模型啟用**。RequireResources 強制約束,需自行確保資源完整。ll-Ssss-CC(如 zh-TW、en-US)。掌握 Feature.xml 結構,是開發可部署、可國際化、可相依管理的 SharePoint Feature 基石。