How to get the active project?

  • Thread starter Thread starter BasmaWed
  • Start date Start date
B

BasmaWed

Guest
Hi,

I have this method that returns the active project:


namespace Utils
{

internal static class LocalUtils
{

internal static EnvDTE.DTE dte => CoreUtility.ServiceProvider.GetService(typeof(DTE)) as EnvDTE.DTE;

internal static VSProjectNode GetActiveProject()
{
Array projects = LocalUtils.dte.ActiveSolutionProjects as Array;

if (projects?.Length > 0)
{
Project project = projects.GetValue(0) as Project;
return project?.Object as VSProjectNode;
}
return null;
}
But I get NullReferenceException in this line:

internal static EnvDTE.DTE dte => CoreUtility.ServiceProvider.GetService(typeof(DTE)) as EnvDTE.DTE;

Continue reading...
 
Back
Top