VSIX: Getting DTE object

前端 未结 4 1528
执念已碎
执念已碎 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条回答
  •  -上瘾入骨i
    2020-12-15 00:25

    I see a couple of problems here:

    • You really should be using __VSSPROPID4.VSSPROPID_ShellInitialized (defined in Microsoft.VisualStudio.Shell.Interop.10.0) instead of -9083 for readability
    • You should be checking for ShellInitialized being set to true (although checking for Zombie going to false is correct)
    • Keep in mind that ShellInitialized will change to true once...on startup of VS. Checking for it is the right approach if your package is registered to auto-load on startup (which may happen before VS is fully ready to go). However, most packages should not auto-load on startup, but rather load on-demand from some user action requiring your package code. You can then check for the DTE service in your package class Initialize method.

提交回复
热议问题