简体   繁体   English

手动调用Visual Studio的可视化工具

[英]Invoking Visual Studio's visualizer manually

Scenario 脚本

I've been trying to manually invoke Visual Studio's visualizer from code/immediate window, so far without any luck. 我一直试图从代码/即时窗口手动调用Visual Studio的可视化工具,到目前为止没有任何运气。

I've written a simple console application with the following code: 我用以下代码编写了一个简单的控制台应用程序:

var dataset = new System.Data.DataSet();

Then I added dataset into the Watch Window and visualized it using the DataSet Visualizer . 然后我将数据集添加到监视窗口并使用DataSet Visualizer将其可视化 As expected, that worked. 正如所料,这是有效的。

Once I've done that, I entered the following code into the immediate window: 完成后,我将以下代码输入到即时窗口中:

new Microsoft.VisualStudio.DebuggerVisualizers.VisualizerDevelopmentHost(dataset, typeof(EnhancedDataSetVisualizer.DataSetVisualizer)).ShowVisualizer();

Which caused the following exception ( full exception ): 这导致以下异常( 完全异常 ):

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Debugger.DataSetVisualizer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.Debugger.DataSetVisualizer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, 
….

Which is really strange to me because if I look into Debug->Widnow->Modules in Visual Studio, I see that DataSetVisualizer.dll is already loaded: 这对我来说真的很奇怪,因为如果我在Visual Studio中查看Debug-> Widnow-> Modules ,我会看到已经加载了DataSetVisualizer.dll:

Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll   C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers\Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll No  No  Cannot find or open the PDB file.       18  10.0.30319.1    18/03/2010 12:06 PM 77AB0000-77AC2000   [6784] PresentingBugAid.vshost.exe: Managed (v2.0.50727)    

Yet, it tries to load it, and fails. 然而,它试图加载它,并失败。 I've tried to examine the fusion log ( full log ): 我试图检查融合日志( 完整日志 ):

…
file:///C:/SVN/Debugger/src/Test/PresentingMyTest/PresentingMyTest/bin/Debug/Microsoft.VisualStudio.Debugger.DataSetVisualizer.DLL.
LOG: Attempting download of new URL 
...

And just for the sake of trying I copied Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll to c:\\SVN\\Debugger\\src\\Test\\PresentingMyTest\\PresentingMyTest\\bin\\Debug\\ then retried the scenario above. 只是为了尝试我将Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll复制到c:\\ SVN \\ Debugger \\ src \\ Test \\ PresentingMyTest \\ PresentingMyTest \\ bin \\ Debug \\然后重试上面的场景。 This time it seemed to work, the visualization appeared, yet, it froze the whole application. 这次似乎工作,可视化出现了,但它冻结了整个应用程序。 Moreover, trying it again no longer showed the visualization at all. 而且,再次尝试它不再显示可视化。

Afterthoughts 后记

I realized after a while that what I did might be weird - Visual Studio's Visualizers are designed to run inside the debugger's process (devenv.exe), yet, in my case I've been trying to force the visualizer to load in the debuggee (PresentingMyTest.exe). 过了一段时间我意识到我所做的可能很奇怪 - Visual Studio的Visualizer被设计为在调试器的进程(devenv.exe)中运行,但在我的情况下,我一直试图强制可视化器加载到调试对象中( PresentingMyTest.exe)。 While it doesn't explain why it tried to load Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll even though it was loaded, I guess it explains why it didn't work in general. 虽然它没有解释为什么它试图加载Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll,即使它已加载,我想它解释了为什么它一般不起作用。

Another solution I considered to try is skipping VisualizerDevelopmentHost completely, and instead, invoking via reflection DataSetVisualizer's Show method directly, a method that any visualization must have. 我考虑尝试的另一个解决方案是完全跳过VisualizerDevelopmentHost,而是直接通过反射DataSetVisualizer的Show方法调用,这是任何可视化必须具有的方法。 Is that a good idea? 这是一个好主意吗?

I realize the whole scenario is quite unsupported, yet, it is quite important for my project and I'be happy to hear additional thoughts and things I can try to make it work. 我意识到整个场景都没有得到支持,但是,这对我的项目来说非常重要,我很高兴听到其他想法和事情,我可以尝试使其工作。

Thanks! 谢谢!

Maybe it's possible to use 'Microsoft.VisualStudio.DebuggerVisualizers.VisualizerDevelopmentHost' type and particular ShowVisualizer() method? 也许可以使用'Microsoft.VisualStudio.DebuggerVisualizers.VisualizerDevelopmentHost'类型和特定的ShowVisualizer()方法? I haven't had time to play around vizualization debuggers, so this is just a wild guess. 我没有时间玩vizualization调试器,所以这只是一个疯狂的猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM