Add assembly reference – Extending Visual Studio SharePoint development tools tip #2
SharePoint 2010, Tips & Tricks, Visual Studio 2010If 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.
References
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=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <EmbedInteropTypes>True</EmbedInteropTypes> </Reference> <Reference Include="VSLangProj, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <EmbedInteropTypes>True</EmbedInteropTypes> </Reference>
Code
internal static void AddReference(Project project, string reference)
{
VSLangProj.VSProject vsProject = (VSLangProj.VSProject)project.Object;
vsProject.References.Add(reference);
}
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.
Example
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.

















Recent Comments