Share via


Solution2.Count Property

Gets a value indicating the number of projects in the solution.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
ReadOnly Property Count As Integer
int Count { get; }
property int Count {
    int get ();
}
abstract Count : int with get
function get Count () : int

Property Value

Type: Int32
The number of projects in the solution.

Examples

For information on how to run this add-in code, see How to: Compile and Run the Automation Object Model Code Examples.

The following example counts the number of projects in an open solution.

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)
    SolutionCountExample(_applicationObject)
End Sub

Sub SolutionCountExample(ByVal dte As DTE2)
    ' This add-in counts the projects in a solution.
    ' Open a solution in Visual Studio before running this
    ' example.
   Try
       Dim soln As Solution2 = CType(_applicationObject.Solution, _
       Solution2)
        ' List the number of projects.
        MsgBox("Number of projects in" & soln.FullName & " is: " _
        & vbCr & soln.Count)
    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.
    SolutionCount((DTE2)_applicationObject);
}

public void SolutionCount(DTE2 dte)
{
    // This add-in counts the projects in a solution.
    // Open a soultion in Visual Studio before running this
    // example.
    Try
    {
        Solution2 soln = (Solution2)_applicationObject.Solution;
        // List the number of projects.
        MessageBox.Show("Number of projects in" + soln.FullName 
+ " is: " + "\n" + soln.Count);
    }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

.NET Framework Security

See Also

Reference

Solution2 Interface

EnvDTE80 Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples