Solution2 介面

代表整合式開發環境 (IDE) 中所有的專案和適用整個方案的屬性。

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

語法

'宣告
<GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")> _
Public Interface Solution2 _
    Inherits _Solution
[GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")]
public interface Solution2 : _Solution
[GuidAttribute(L"FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")]
public interface class Solution2 : _Solution
[<GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")>]
type Solution2 =  
    interface
        interface _Solution
    end
public interface Solution2 extends _Solution

Solution2 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 AddIns (繼承自 _Solution)。
公用屬性 AddIns 取得 AddIns 集合,此集合包含目前所有與方案相關的可用增益集。
公用屬性 Count (繼承自 _Solution)。
公用屬性 Count 取得數值,指出方案中專案的數目。
公用屬性 DTE (繼承自 _Solution)。
公用屬性 DTE 取得最上層的擴充性物件。
公用屬性 Extender[String] (繼承自 _Solution)。
公用屬性 Extender[String] 取得要求的擴充項物件 (如果適用於這個物件)。
公用屬性 ExtenderCATID (繼承自 _Solution)。
公用屬性 ExtenderCATID 取得物件的擴充項分類 ID (CATID)。
公用屬性 ExtenderNames (繼承自 _Solution)。
公用屬性 ExtenderNames 取得物件的可用擴充項清單。
公用屬性 FileName (繼承自 _Solution)。
公用屬性 FileName 基礎架構。僅限 Microsoft 內部使用。
公用屬性 FullName (繼承自 _Solution)。
公用屬性 FullName 取得物件檔案的完整路徑和名稱。
公用屬性 Globals (繼承自 _Solution)。
公用屬性 Globals 取得 Globals 物件,此物件包含可能儲存在方案檔 (.sln)、專案檔,或使用者設定檔資料中的任何變數值。
公用屬性 IsDirty (繼承自 _Solution)。
公用屬性 IsDirty 基礎架構。僅限 Microsoft 內部使用。
公用屬性 IsOpen (繼承自 _Solution)。
公用屬性 IsOpen 取得值,指出某一方案是否為開啟。
公用屬性 Parent (繼承自 _Solution)。
公用屬性 Parent 取得 Solution2 物件的直接上層父物件。
公用屬性 Projects (繼承自 _Solution)。
公用屬性 Projects 取得方案中目前專案的集合。
公用屬性 Properties (繼承自 _Solution)。
公用屬性 Properties 取得與 Solution2 物件有關的所有屬性集合。
公用屬性 Saved (繼承自 _Solution)。
公用屬性 Saved 取得或設定值,指出方案是否自從上次存檔或開啟後就未被修改過。
公用屬性 SolutionBuild (繼承自 _Solution)。
公用屬性 SolutionBuild 取得方案的 SolutionBuild 物件,它代表方案層級之組建 Automation 模型的根物件。
公用屬性 TemplatePath[String] (繼承自 _Solution)。
公用屬性 TemplatePath[String] 已由 GetProjectTemplate 取代。

回頁首

方法

  名稱 說明
公用方法 AddFromFile(String, Boolean) (繼承自 _Solution)。
公用方法 AddFromFile(String, Boolean) 根據已經儲存於系統中的專案檔,將專案加入至方案。
公用方法 AddFromTemplate(String, String, String, Boolean) (繼承自 _Solution)。
公用方法 AddFromTemplate(String, String, String, Boolean) 將現有的專案檔及其所包含的一切項目或子目錄,複製至指定的位置並加入至方案中。
公用方法 AddSolutionFolder 將方案資料夾加入至 ProjectItems 集合。
公用方法 Close(Boolean) (繼承自 _Solution)。
公用方法 Close(Boolean) 關閉目前的方案。
公用方法 Create(String, String) (繼承自 _Solution)。
公用方法 Create(String, String) 在指定的目錄中以指定的名稱,建立一個空白方案。
公用方法 FindProjectItem(String) (繼承自 _Solution)。
公用方法 FindProjectItem(String) 尋找專案中的一個項目。
公用方法 GetEnumerator() (繼承自 _Solution)。
公用方法 GetEnumerator() 傳回列舉集合中的項目。
公用方法 GetProjectItemTemplate 傳回指定專案項目範本的路徑。
公用方法 GetProjectTemplate 傳回指定專案範本的路徑。
公用方法 Item(Object) (繼承自 _Solution)。
公用方法 Item(Object) 傳回 Projects 集合的索引成員。
公用方法 Open(String) (繼承自 _Solution)。
公用方法 Open(String) 會開啟指定的方案。
公用方法 ProjectItemsTemplatePath(String) (繼承自 _Solution)。
公用方法 ProjectItemsTemplatePath(String) 已由 GetProjectItemTemplate 取代。
公用方法 Remove(Project) (繼承自 _Solution)。
公用方法 Remove(Project) 將指定的專案從方案中移除。
公用方法 SaveAs(String) (繼承自 _Solution)。
公用方法 SaveAs(String) 儲存方案。

回頁首

備註

這個介面包含 IDE 目前執行個體中所有專案,以及組建組態等所有適用整個方案之屬性的集合。 不論是包裝專案、子專案,還是最上層專案,它都會針對每個專案包含一個專案項目。

您可以使用 DTE.Solution 屬性,尋找開啟的方案。 若要參考如 MiscFiles 或 SolutionItems 的虛擬專案,請使用 Solution.Item(EnvDTE.Constants.vsProjectKindMisc 或 Solution.Item(EnvDTE.Constants.vsProjectKindSolutionItems。

範例

如需如何執行增益集程式碼的詳細資訊,請參閱 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 Basic Console
    ' project to it.
    Try
        Dim soln As Solution2 = CType(DTE.Solution, Solution2)
        Dim vbTemplatePath As String
        ' This path must exist on your computer.
        ' Replace <file path> below with an actual path.
        Dim vbPrjPath As String = <file path>
        MsgBox("starting")
        ' Get the project template path for a Visual Basic console application project.
        vbTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "VisualBasic")
        ' Create a new Visual Baic Console project using the template obtained 
        ' above.
        soln.AddFromTemplate(vbTemplatePath, vbPrjPath, _
        "New Visual Basic Console Project", False)
        MsgBox("done")
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
//you will need to add this reference to your project as well
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{
        Solution2 soln = (Solution2)_applicationObject.Solution;
        String csTemplatePath;
        // The file path must exist on your computer.
        // Replace <file path> below with an actual path.
        String csPrjPath = <file path>;
    MessageBox.Show("Starting...");
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);
    }
}

請參閱

參考

EnvDTE80 命名空間