I am trying to learn more about creating a VSIX project using the Roslyn VisualStudioWorkspace. I have successfully created a context menu command that appears when right-clicking on a visual studio project. How do I go about getting a reference to the selected project in code without using ENVDTE?
Asked
Active
Viewed 97 times
0
-
Does this answer your question? [How to get reference to 'Roslyn' Workspace object from IVsSolution?](https://stackoverflow.com/questions/23578399/how-to-get-reference-to-roslyn-workspace-object-from-ivssolution) – Ian Kemp Dec 26 '19 at 00:04
1 Answers
0
You can import the visual studio workspace using the MEF
[Import(typeof(VisualStudioWorkspace))]
public VisualStudioWorkspace ImportedWorkspace { get; set; }
see this SO answer for more detail

Jonathon Marolf
- 2,071
- 14
- 16
-
No, perhaps the question needs to be re-worded. I was able to import VisualStudioWorkspace with no problems. I need to determine which project in a solution was selected when invoking the context menu command. – Torrey Garland Dec 27 '19 at 02:06
-
i would re-word your question to state exactly what data you have and what you are trying to get. If you have the [IVsHierarchyItem](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.ivshierarchyitem?view=visualstudiosdk-2019) you can write some code like [this](https://github.com/dotnet/roslyn/blob/6d2888693f62b3628c36be3987c53074e6df6f8f/src/VisualStudio/Core/Def/Implementation/HierarchyItemToProjectIdMap.cs#L24) to get the project Id. However you said you don't want to use DTE apis, which would be required to do this. – Jonathon Marolf Dec 27 '19 at 08:11