SolutionFolder 介面
方案資料夾是可以讓開發人員能更妥善組織大型應用程式的專案容器,。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
<GuidAttribute("F8F69788-267C-4408-8967-74F26108C438")> _
Public Interface SolutionFolder
[GuidAttribute("F8F69788-267C-4408-8967-74F26108C438")]
public interface SolutionFolder
[GuidAttribute(L"F8F69788-267C-4408-8967-74F26108C438")]
public interface class SolutionFolder
[<GuidAttribute("F8F69788-267C-4408-8967-74F26108C438")>]
type SolutionFolder = interface end
public interface SolutionFolder
SolutionFolder 型別會公開下列成員。
屬性
名稱 | 說明 | |
---|---|---|
DTE | 取得最上層的擴充性物件。 | |
Hidden | 設定或取得隱藏的方案屬性。 | |
Parent | 取得 Find 物件的直接上層父物件。 |
回頁首
方法
名稱 | 說明 | |
---|---|---|
AddFromFile | 將現有專案加入至方案資料夾。 | |
AddFromTemplate | 依據專案範本將新專案加入至方案資料夾。 | |
AddSolutionFolder | 將方案資料夾加入至 ProjectItems 集合。 |
回頁首
備註
在 Visual Studio 2005 中,方案除了可以包含專案資料夾之外,還可以包含方案資料夾。 方案資料夾是專案容器,可讓開發人員能更妥善組織大型應用程式。
方案的 Projects 屬性會傳回 Project 物件的集合。 每個個別專案都有 Kind 屬性,此屬性可設為 vsProjectKindSolutionFolder。 若要取得 SolutionFolder 介面,請呼叫 Project.Object,然後將傳回的物件轉型成 SolutionFolder 型別。
範例
這個範例中,會建立新方案資料夾,並從現有檔案中加入專案至此資料夾。 在執行這個範例之前,請先在主磁碟機 (在範例中為 "C:") 以外的地方建立一個 "Projects" 資料夾,並在其中建立名為 "ClassLibrary1" 的 Visual C# 類別庫專案。 執行這個增益集之前,您也必須開啟 Visual Studio 整合式開發環境 (IDE) 中的專案。
如需如何像執行增益集一般,執行這個範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
Imports EnvDTE
Imports EnvDTE80
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)
solnFolderAddFromFileExample(_applicationObject)
End Sub
Sub solnFolderAddFromFileExample(ByVal dte As DTE2)
' Before running this example, create a "Projects" folder
' off your main drive (C: in this example), and create a C#
' class library project, named ClassLibrary1 in that folder.
Dim soln As Solution2 = CType(_applicationObject.Solution _
, Solution2)
Dim prj As Project
Dim SF As SolutionFolder
Try
Dim prjPath As String = _
"C:\Projects\ClassLibrary1\ClassLibrary1\ClassLibrary1.csproj"
' Open a project in the Visual Studio IDE before running
' this add-in.
' Add a solution folder.
prj = soln.AddSolutionFolder("A new soln folder")
SF = CType(prj.Object, SolutionFolder)
' Add a project to the new solution folder.
SF.AddFromFile(prjPath)
MsgBox("Added a new solution folder that contains a _
C# project named ClassLibrary1.")
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
solnFolderAddFromFileExample(_applicationObject);
}
public void solnFolderAddFromFileExample(DTE2 dte)
{
// Before running this example, create a "Projects" folder
// off your main drive (C: in this example), and create a C#
// class library project, named ClassLibrary1 in that folder.
Solution2 soln = (Solution2)_applicationObject.Solution;
Project prj;
SolutionFolder SF;
try
{
String prjPath =
"C:\\Projects\\ClassLibrary1\\ClassLibrary1\\ClassLibrary1.csproj";
// Open a project in the Visual Studio IDE before running
// this add-in.
// Add a solution folder.
prj = soln.AddSolutionFolder("A new soln folder");
SF = (SolutionFolder)prj.Object;
// Add a project to the new solution folder.
SF.AddFromFile(prjPath);
MessageBox.Show("Added a new solution folder that contains a
C# project named ClassLibrary1.");
}
catch(SystemException ex)
{
MessageBox.Show(ex.ToString());
}
}