Solution4.GetProjectItemTemplates 方法 (String, String)

傳回指定之專案的專案項目範本集合。

命名空間:  EnvDTE100
組件:  EnvDTE100 (在 EnvDTE100.dll 中)

語法

'宣告
Function GetProjectItemTemplates ( _
    Language As String, _
    CustomDataSignature As String _
) As Templates
Templates GetProjectItemTemplates(
    string Language,
    string CustomDataSignature
)
Templates^ GetProjectItemTemplates(
    String^ Language, 
    String^ CustomDataSignature
)
abstract GetProjectItemTemplates : 
        Language:string * 
        CustomDataSignature:string -> Templates 
function GetProjectItemTemplates(
    Language : String, 
    CustomDataSignature : String
) : Templates

參數

  • Language
    型別:System.String
    用以撰寫專案項目範本的語言。
  • CustomDataSignature
    型別:System.String
    與專案項目範本相關聯之任何中繼資料的簽章。

傳回值

型別:EnvDTE90.Templates
包含所有專案項目範本名稱的範本集合。

實作

Solution3.GetProjectItemTemplates(String, String)

備註

專案範本會儲存為 zip 檔。 這個方法會以名稱和語言要求專案,並且傳回範本路徑。

GetProjectItemTemplate 的參數可以藉由不同的方式加以提供,如下所示:

  • 將智慧型裝置 Visual Basic Virtual Project 的 GUID 當做 Language 參數傳入,並將 zip 檔的檔名當做 TemplateName 傳入。

    GetProjectItemTemplate("NETCFv2-Class.zip", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");
    
  • 將智慧型裝置 Visual Basic Virtual Project 的 GUID 當做 Language 參數,並將 "Class" 字串當做 TemplateName 傳入。 這個字串 "Class" 係衍生自資料夾階層架構,並且被稱為使用者介面 (UI) 字串。 其他的 UI 字串為 "HTML Page" 和 "Splash Screen", 這些 UI 字串會因為地區設定而異。 因此傳遞 TemplateName 參數最安全的方式便是使用 zip 檔的名稱。

    GetProjectItemTemplate("Class", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");
    
  • 將 "VisualBasic" 當做 Language 參數,並將 zip 檔的檔名當做 TemplateName 參數進行傳遞。 因為對智慧型裝置而言,NETCFv2-Class.zip 為獨一無二的檔名,所以這個作法可行。

    GetProjectItemTemplate("NETCFv2-Class.zip", "VisualBasic/SmartDevice-NETCFv2");
    

您也可以為專案項目建立自訂範本。 若要指定用來儲存範本的目錄,請按一下 [工具] 功能表上的 [選項], 然後在 [選項] 對話方塊的左窗格中,按一下 [專案和方案], 在 [Visual Studio 使用者項目範本位置] 方塊中輸入範本的路徑, 或者,您也可以接受預設位置。

自訂範本必須具有獨特的檔案名稱,不能與下列位置定義的檔案名稱相互衝突:

<drive>:\Program Files\Microsoft Visual Studio 9\Common7\IDE\ItemTemplates\Language.

請確定要使用長檔名 (不能使用 8dot3)。 如需詳細資訊,請參閱建立專案範本和項目範本

範例

如需如何執行增益集程式碼的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    SolutionExample(_applicationObject)
End Sub

Sub SolutionExample(ByVal dte As DTE2)
    ' This function creates a solution and adds a Visual C# Console
    ' project to it.
    Try
        Dim soln As Solution4 = CType(DTE.Solution, Solution4)
        Dim csTemplatePath As String
        ' This path must exist on your computer.
        ' Replace <file path> below with an actual path.
        Dim csPrjPath As String = "<file path>"
        MsgBox("starting")
        ' Get the project template path for a C# console project.
        csTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "CSharp")
        ' Create a new C# Console project using the template obtained 
        ' above.
        soln.AddFromTemplate(csTemplatePath, csPrjPath, _
        "New CSharp Console Project", False)
        MsgBox("done")
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    SolutionExample((DTE2)_applicationObject);
}

public void SolutionExample(DTE2 dte)
{
    // This function creates a solution and adds a Visual C# Console
    // project to it.
    try{
        Solution4 soln = (Solution4)_applicationObject.Solution;
        String csTemplatePath;
        // The file path must exist on your computer.
        // Replace <file path> below with an actual path.
        String csPrjPath = "<file path>";
        "<file path>MessageBox.Show("Starting...");
        "<file path>"<file path>csTemplatePath = 
          soln.GetProjectTemplate("ConsoleApplication.zip", "CSharp");
        // Create a new C# Console project using the template obtained 
        // above.
        soln.AddFromTemplate(csTemplatePath, csPrjPath,
          "New CSharp Console Project", false);
        MessageBox.Show("Done!");
    }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

.NET Framework 安全性

請參閱

參考

Solution4 介面

GetProjectItemTemplates 多載

EnvDTE100 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例