3

I'm coding an extension in C# using the Managed Extensibility Framework (MEF).
How can I get the current open solution name or the project names?

The class i'm been digging deep in is the IWpfTextView but I didn't find it.

Jeremi Stadler
  • 2,567
  • 4
  • 21
  • 22

1 Answers1

8

If you have a Package class in your assembly, you can do:

DTE2 = Package.GetGlobalService(typeof(SDTE)) as DTE2; string fullName = dte.Solution.FullName;

Otherwise you can get the DTE via: DTE dte = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE") as DTE; string fullName = dte.Solution.FullName;

and I see people talk about a more 'MEF' oriented way of the getting the DTE but I've not tried it..

Once you have the DTE object you can then traverse the projects with the solution.

ref: VSIX: Getting DTE object ref: http://msdn.microsoft.com/en-us/library/envdte.solution.aspx

Community
  • 1
  • 1
Stephen Gennard
  • 1,910
  • 16
  • 21