VSIX: Getting DTE object

前端 未结 4 1524
执念已碎
执念已碎 2020-12-14 23:43

My Visual Studio package requires the use of an EnvDTE.DTE variable, but it always gets back as null. After reading up on many hacks, all of them say to use the OnShellPrope

4条回答
  •  [愿得一人]
    2020-12-15 00:31

    I know you selected an answer already but you did specify that you didnt want to use the MEF so I thought I would post an alternative just for the sake of completeness....;p

    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using EnvDTE;
    using EnvDTE80;
    
    namespace DTETesting
    {
        class Program
        {
            const string ACTIVE_OBJECT = "VisualStudio.DTE.10.0";
            static void Main(string[] args)
            {
                EnvDTE80.DTE2 MyDte;
                MyDte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject(ACTIVE_OBJECT);
                Console.WriteLine("The Edition is "+MyDte.Edition);
                Console.ReadLine();
            }
        }
    }
    
    

提交回复
热议问题