Add assembly reference – Extending Visual Studio SharePoint development tools tip #2

If you work a lot with custom assemblies that you reference from your SharePoint Projects in Visual Studio SharePoint development tools, you might want to create an extension that does that automatically for you.


In your project you need the following assembly references:

  • EnvDTE (Enable Interop Types: True)
  • VSLangProj (Enable Interop Types: True)

You can also paste the following snippet into your project file:

<Reference Include="EnvDTE, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Reference Include="VSLangProj, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">


internal static void AddReference(Project project, string reference)
    VSLangProj.VSProject vsProject = (VSLangProj.VSProject)project.Object;

You can add an assembly reference using different methods. For more information about the valid values for the reference parameter see the References.Add(string) method page on MSDN.


Project activeProject = GetActiveProject();
AddReference(activeProject, "Microsoft.SharePoint.Client");
AddReference(activeProject, "Microsoft.SharePoint.Client.Runtime");

The above example uses the GetActiveProject() method to retrieve the active project.

Technorati Tags: Visual Studio 2010,SharePoint 2010