Home > Plug-in Development > How to add assembly and project references to a specific project using DXCore

How to add assembly and project references to a specific project using DXCore

April 19th, 2012

To add an assembly reference, you first require a reference to the target project. To get one, you can use the Source Model DXCore service, for example:

ProjectElement projectElement = CodeRush.Source.ActiveProject;

This will return the active project. If there is no active project (e.g. no source files are opened) or you would like to find one by its name or a full path, use the following calls:

ProjectElement projectElement1 = CodeRush.Source.ActiveSolution.GetProject("ProjectName");
ProjectElement projectElement2 = CodeRush.Source.ActiveSolution.GetProjectByFullName("ProjectPath");

Then, to add an assembly reference you can use methods of the ProjectElement DXCore class:


This call will find and add a known (in the GAC) assembly to the project. If an assembly is not inside the GAC or public assembly folders, you can manually create an assembly reference, specify its full path and add it to the project as follows:

AssemblyReference assemblyReference = new AssemblyReference("assembly_path");

To add a project reference, you can use the DXCore Solution service and its AddProjectReference() method and specify two projects:

  • The name of the target project to which to add a reference as a first parameter.
  • The name of the project reference to add as a second parameter:
CodeRush.Solution.AddProjectReference("TargetProjectName", "ReferenceProjectName");
Products: DXCore
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Apr/19/2012
ID: D145

Similar Posts: