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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s