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) 中打开项目。
有关如何作为外接程序运行此示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例。
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());
}
}