Share via


HOW TO:以程式設計方式更新應用程式資訊清單組件路徑 (2003 系統)

更新:2007 年 11 月

適用於

本主題中的資訊僅適用於指定的 Visual Studio Tools for Office 專案和 Microsoft Office 版本。

專案類型

  • 文件層級專案

Microsoft Office 版本

  • Microsoft Office 2003

如需詳細資訊,請參閱依應用程式和專案類型提供的功能

您可以使用 Visual Studio Tools for Office 執行階段中的物件模型 (Object Model),以程式設計的方式更新內嵌在文件中,同時也是文件層級自訂一部分的應用程式資訊清單。

當您變更組件的路徑時,必須建立新的應用程式資訊清單,並取代包含過時路徑的資訊清單。您可以在組件的路徑中使用環境變數,例如 %ProgramFiles% or %UserProfile%。

您必須將操作物件模型的程式碼放置在新的專案 (而非 Visual Studio Tools for Office 方案) 中,例如放在主控台應用程式 (Console Application) 或 Windows Form 專案中。Visual Studio Tools for Office 包含一項範例,此範例會示範如何建立可用來編輯內嵌應用程式資訊清單的工具。如需詳細資訊,請參閱ServerDocument 範例

有另一個用於更新資訊清單的模型,與修改伺服器上的 XML 檔案有關。如需詳細資訊,請參閱HOW TO:變更文件層級自訂的位置 (2003 系統)

注意事項:

此主題並不適用於應用程式層級增益集,因為這些增益集並未使用內嵌應用程式資訊清單。若要變更增益集組件的路徑,請使用文字編輯器來更新位於用戶端電腦上的應用程式資訊清單。如需詳細資訊,請參閱Office 方案的應用程式資訊清單 (2003 系統)。如需應用程式層級增益集和文件層級自訂的詳細資訊,請參閱 文件層級自訂的架構

若要以程式設計的方式變更組件的路徑

  1. 在您的物件模型管理專案中加入對 Microsoft.VisualStudio.Tools.Office.Runtime.v9.0 的參考 (如果還沒有該參考)。

  2. 將執行階段的 Imports 或 using 陳述式加入至程式碼檔的最上方。

    Imports Microsoft.VisualStudio.Tools.Applications.Runtime
    
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    
  3. 呼叫 ServerDocument 類別的靜態 AddCustomization 方法,然後傳入必要的引數。您應該先呼叫 RemoveCustomization 方法,從文件移除任何現有的 Visual Studio Tools for Office 自訂,否則 AddCustomization 將會擲回 InvalidOperationException

    Dim solutionDocument As String = "C:\Documents\ExcelApplication.xls"
    Dim assemblyName As String = "ExcelApplication.dll"
    Dim manifestPath As String = "\\serversame\deployshare\ExcelApplication.application"
    Dim applicationVersion As String = "1.0.0.1"
    
    If ServerDocument.IsCustomized(solutionDocument) Then
        ServerDocument.RemoveCustomization(solutionDocument)
    End If
    
    ServerDocument.AddCustomization( _
        solutionDocument, assemblyName, manifestPath, _
        applicationVersion, False)
    
    string solutionDocument = @"C:\Documents\ExcelApplication.xls";
    string assemblyName = "ExcelApplication.dll";
    string manifestPath = @"\\servername\deployshare\ExcelApplication.application";
    string applicationVersion = "1.0.0.1";
    
    if (ServerDocument.IsCustomized(solutionDocument))
    {
        ServerDocument.RemoveCustomization(solutionDocument);
    }
    
    ServerDocument.AddCustomization(
        solutionDocument, assemblyName, manifestPath, 
        applicationVersion, false);
    

請參閱

工作

HOW TO:以程式設計方式變更部署資訊清單的路徑 (2003 系統)

HOW TO:從文件移除 Managed 程式碼擴充 (2003 系統)

概念

Office 方案中的應用程式和部署資訊清單

部署 Office 方案 (2003 系統)

參考

Office 方案的應用程式資訊清單 (2003 系統)

Office 方案的部署資訊清單 (2003 系統)