Reference3.SourceProject Property
Gets a Project object if the reference is a project. Otherwise, it returns Nothing (a null object).
Namespace: VSLangProj80
Assembly: VSLangProj80 (in VSLangProj80.dll)
Syntax
'Declaration
ReadOnly Property SourceProject As Project
Project SourceProject { get; }
property Project^ SourceProject {
Project^ get ();
}
abstract SourceProject : Project
function get SourceProject () : Project
Property Value
Type: EnvDTE.Project
Returns a Project object.
Implements
Remarks
For one project to use objects built by a second project, the first project must contain a reference to the second project. In such a case, the SourceProject property can return a Project object for the second project.
Examples
This example iterates through all the references and displays the name of the SourceProject, if there is one. To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples. Open a Visual Basic or Visual C# project before running this example.
Imports VSLangProj
Imports VSLangProj2
Imports VSLangProj80
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)
DisplaySourceProjectName(applicationObject)
End Sub
Public Sub DisplaySourceProjectName(ByVal dte As DTE2)
' The first project is a Visual Basic or C# project.
Dim vsProject As VSProject2 =_
CType(applicationObject.Solution.Projects.Item(1).Object, _
VSProject2)
Dim aRef As Reference3
Dim refStr As String
refStr = ""
Dim project As EnvDTE.Project
For Each aRef In vsProject.References
project = aRef.SourceProject
If project Is Nothing Then
refStr += (aRef.Name & " has no source project." & vbCr _
& vbCr)
Else
refStr += (aRef.Name & " has a source project named " _
& project.Name & vbCr & vbCr)
End If
Next
MsgBox(refStr)
End Sub
using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
applicationObject = (DTE2)application;
addInInstance = (AddIn)addInInst;
DisplaySourceProjectName(((DTE2)applicationObject));
}
public void DisplaySourceProjectName(DTE2 dte)
{
// The first project is a Visual Basic or C# project.
VSProject2 aProject =
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));
Reference3 aRef = null;
string refStr = null;
refStr = "";
EnvDTE.Project project = null;
foreach (VSLangProj80.Reference3 temp in aProject.References)
{
aRef = temp;
project = aRef.SourceProject;
if (project == null)
{
refStr += (aRef.Name + " has no source project." + "\n"
+ "\n");
}
else
{
refStr += (aRef.Name + " has a source project named "
+ project.Name + "\n" + "\n");
}
}
MessageBox.Show(refStr);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.