【发布时间】:2020-12-09 13:25:19
【问题描述】:
使用像[System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE") 这样的COM 方法,我可以很好地导航Visual Studio DTE 对象模型。例如,从DTE 对象我可以得到Debugger,然后是LocalProcesses,然后是Process 对象。但我需要派生的Process2 接口,调用Attach2("<my debug engine>")。
我找不到获取我想要的接口的方法,一个简单的转换会导致运行时错误:Cannot convert the "System.__ComObject" value of type "System.__ComObject#{5c5a0070-f396-4e37-a82a-1b767e272df9}" to type "EnvDTE80.Process2"。
PS> $dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE")
PS> $p = $dte.Debugger.LocalProcesses | where {$_.ProcessID -eq 11212}
PS> $p
Name : C:\Program Files\IIS Express\iisexpress.exe
ProcessID : 11212
Programs : System.__ComObject
DTE : System.__ComObject
Parent : System.__ComObject
Collection : System.__ComObject
PS> [EnvDTE80.Process2]$p2 = $p
Cannot convert the "System.__ComObject" value of type "System.__ComObject#{5c5a0070-f396-4e37-a82a-1b767e272df9}" to type "EnvDTE80.Process2".
At line:1 char:1
+ [EnvDTE80.Process2]$p2 = $p
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
+ FullyQualifiedErrorId : RuntimeException
【问题讨论】:
标签: visual-studio powershell com envdte