Add reference path to IProject?
-
Saturday, March 10, 2012 8:44 AM
Hi,
Is there any way I can add folder reference path using IProject object? Similarly as we can do it from Project Properties window.
Adil Mughal (MCPD, MCT, MVP) - http://AdilMughal.com
All Replies
-
Wednesday, March 14, 2012 8:23 PMOwner
Hi Adil - I don't think it is possible to add "folder" reference paths to an IProject. I could be wrong, but I think this is because folder reference path is a VS concept while the Roslyn Workspace APIs (i.e. IWorkspace, IProject, ISolution) only represent the view of solutions, projects, documents that the C# and VB language services consume. Take a look at Dustin's answer on this thread for another VS feature (i.e. nested docuements) that is not supported in the Workspace APIs. I think his answer would also apply to this thread.
You can add reference to a particular assembly programatically as follows -
IProject project = ...; ISolution solution = project.Solution; solution = solution.AddMetadataReference(project.Id, new AssemblyFileReference(@"D:\MyAssembly.dll"));
You could also use solution.AddMetadataReferences() which would allow you to add multiple assembly references in one go. Note that the objects are immutable. So anytime you make any changes to an existing ISolution or IProject object, you would get back a new ISolution or IProject object with your changes.
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team
- Edited by Shyam NamboodiripadMicrosoft Employee, Owner Wednesday, March 14, 2012 8:51 PM
- Edited by Shyam NamboodiripadMicrosoft Employee, Owner Wednesday, March 14, 2012 8:52 PM
- Edited by Shyam NamboodiripadMicrosoft Employee, Owner Wednesday, March 14, 2012 8:54 PM
- Marked As Answer by Adil MughalMVP Saturday, March 17, 2012 4:44 PM
-
Saturday, March 17, 2012 4:44 PM

