Solution2 接口

更新:2007 年 11 月

表示集成开发环境 (IDE) 中所有的项目和解决方案属性。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
<GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")> _
Public Interface Solution2 _
    Implements _Solution
用法
Dim instance As Solution2
[GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")]
public interface Solution2 : _Solution
[GuidAttribute(L"FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")]
public interface class Solution2 : _Solution
public interface Solution2 extends _Solution

备注

Solution 对象是 IDE 当前实例中所有的项目和所有解决方案属性(如生成配置)的集合。Solution 对象包含每个项目的项目元素,不管这些项目是打包项目、子项目还是顶级项目。

使用 DTE.Solution 引用此对象。若要引用虚项目(如 MiscFiles 或 SolutionItems),请使用 Solution.Item(EnvDTE.Constants.vsProjectKindMisc) 或 Solution.Item(EnvDTE.Constants.vsProjectKindSolutionItems)。

示例

有关如何运行此外接程序代码的信息,请参见如何:编译和运行自动化对象模型代码示例

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 Solution2 = CType(DTE.Solution, Solution2)
        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{
        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>";
    "<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);
    }
}

另请参见

参考

Solution2 成员

EnvDTE80 命名空间