如何调试 Visual Studio 扩展
我正在为 Visual Studio 2010 编写 VSIX 扩展,但不知道如何调试它。
一种明显的方法是输出消息。扩展模板使用 Trace.WriteLine()
。但是在哪里可以找到它的输出呢?
I'm just writing a VSIX extension for Visual Studio 2010 and can't figure out how to debug it.
One obvious method is to output messages. Extension template uses Trace.WriteLine()
. But where to find it's output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Visual Studio Extensions 可以像任何其他应用程序一样进行调试。您只需设置调试体验即可使用加载的扩展启动 devenv。尝试以下
单击“
启动外部程序”
单选按钮。将其指向 devenv.exe 二进制文件。在我的机器上它位于在非 x64 计算机上,您可以删除“(x86)”部分。
然后将命令行参数设置为
/rootsuffix Exp
。这告诉 Visual Studio 使用实验配置单元而不是正常配置配置单元。默认情况下,VSIX 扩展在构建时会在实验配置单元中注册自己。现在您可以按 F5,它将启动 Visual Studio,并将您的 VSIX 作为可用扩展。
Visual Studio Extensions can be debugged like any other application. You just need to setup the debug experience to launch devenv with the loaded extension. Try the following
Click on the radio button for
Start External Program
. Point it to the devenv.exe binary. On my machine it's located atOn a non x64 machine though you can remove the " (x86)" portion.
Then set the command line arguments to
/rootsuffix Exp
. This tells Visual Studio to use the experimental hive instead of the normal configuration hive. By default VSIX extensions when built will register themselves in the experimental hive.Now you can F5 and it will start Visual Studio with your VSIX as an available extension.
@JaredPar 接受的答案在技术上是正确的,但受到以下事实的影响:您需要为每个开发人员重做它,每次您获得代码的新副本,以及任何时候
csproj.user
文件被删除。当您这样做时,设置将保存在csproj.user
文件中。更好的选择是将设置放入
csproj
文件中,这样它们就不会丢失。不幸的是,Visual Studio 不允许您自动执行此操作,因此您需要手动添加设置。幸运的是,任何项目的设置都是相同的。右键单击并卸载项目,然后再次右键单击并编辑
csproj
项目文件。在 XML 中,将以下内容添加到第一个PropertyGroup
中,例如紧接在TargetFramework
之后。这样做有以下优点;
正如 @MBulli 在评论中所述,如果您已在接受的答案中进行了更改,请删除您的
*.csproj.user
文件,因为其中的设置将覆盖您添加到主csproj
文件中的设置。The accepted answer by @JaredPar is technically correct, but suffers from the fact that you need to redo it for every developer, every time you get a fresh copy of the code, and any time the
csproj.user
file is deleted. When you do it that way, the settings are saved in thecsproj.user
file.A better option is to put the settings in the
csproj
file so they are not lost. Unfortunately, Visual Studio does not allow you to do this automatically, so you need to manually add the settings. Luckily, the settings are the same for any project.Right-click and unload the project, then right click again and edit the
csproj
project file file. In the XML, add the following to the firstPropertyGroup
, for example right afterTargetFramework
.This has the following advantages;
As @MBulli states in the comments, if you have made the changes in the accepted answer, delete your
*.csproj.user
file because the settings in it will override the ones you added to the maincsproj
file.OutputWindowHelper.OutputString 方法写入“常规”输出窗口窗格(Ctrl Alt o)。我在 .csproj 引用中添加了这一行,以便在 VS 2013 中获取此内容
另请参阅 这个答案。
The OutputWindowHelper.OutputString method writes to the 'General' output window pane (Ctrl Alt o). I added this line in my .csproj references to get this in VS 2013
Also see this answer.
如果您尝试调试 UnitTestExtension,您还应该将调试器附加到 vstest.*.exe 进程,如所描述的 此处。否则,您可能会看到激活断点,但调试器永远不会命中它。
If you try to debug a UnitTestExtension, you should also attach the debugger to the vstest.*.exe processes like descibed here. Otherwise you might see the activate breakpoint but the debugger will never hit it.