Sdílet prostřednictvím


VCProject.AddAssemblyReference Method

Adds an assembly (.NET) reference to the selected project.

Namespace:  Microsoft.VisualStudio.VCProjectEngine
Assembly:  Microsoft.VisualStudio.VCProjectEngine (in Microsoft.VisualStudio.VCProjectEngine.dll)

Syntax

'Deklarace
Function AddAssemblyReference ( _
    Path As String _
) As Object
Object AddAssemblyReference(
    string Path
)
Object^ AddAssemblyReference(
    [InAttribute] String^ Path
)
abstract AddAssemblyReference : 
        Path:string -> Object 
function AddAssemblyReference(
    Path : String
) : Object

Parameters

  • Path
    Type: System.String
    A string representing the path of the assembly to add.

Return Value

Type: System.Object
The path of the assembly.

Remarks

AddAssemblyReference calls the VSCore service in Visual Studio to identify the MinFrameworkVersion for the added reference. If you call AddAssemblyReference outside of Visual Studio where the VSCore service is not available, then the MinFrameworkVersion is set to eFrameworkVersionUnknown.

Examples

See How to: Compile Example Code for Project Model Extensibility for information about how to compile and run this example.

Adds a .NET assembly reference to your project based on the path to the assembly, if possible.

' Add a reference to Microsoft.VisualStudio.VCProjectEngine and have a 
' Visual C++ project loaded before running this example.
Imports EnvDTE
Imports Microsoft.VisualStudio.VCProjectEngine
Public Module Module1
    Sub Test()
        Dim prj As VCProject
        Dim vcar As VCAssemblyReference
        Dim refcfg As VCReferenceConfiguration

        prj = DTE.Solution.Projects.Item(1).Object
        If prj.CanAddAssemblyReference("C:\Program Files\ _
        Microsoft Visual Studio 8\Common7\IDE\ _
        PublicAssemblies\envdte.dll") Then
           vcar = prj.AddAssemblyReference("C:\Program Files\ _
           Microsoft Visual Studio 8\Common7\IDE\ _
           PublicAssemblies\envdte.dll")
        End If
        refcfg = vcar.ReferenceConfigurations.Item(1)
        MsgBox("Consumable? " & refcfg.ConsumableByDesigner)
    End Sub
End Module

.NET Framework Security

See Also

Reference

VCProject Interface

Microsoft.VisualStudio.VCProjectEngine Namespace