How to: Add References to Visual Studio Project Programmatically

Here is the code snippet for adding reference assemblies to a Visual Studio Project programmatically using EnvDTE (Design Time Extensibility).

Type vsType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); // Targets Visual Studio 2010
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)Activator.CreateInstance(vsType, true);
Solution2 soln = (Solution2)dte.Solution;
Project pProject = pSolution.Projects[0];
pProject.References.Add(string referenceFilePath);

Leave a Comment

Your email address will not be published. Required fields are marked *