如何调试 Visual Studio 扩展

发布于 2025-01-05 06:41:03 字数 127 浏览 0 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泡沫很甜 2025-01-12 06:41:03

Visual Studio Extensions 可以像任何其他应用程序一样进行调试。您只需设置调试体验即可使用加载的扩展启动 devenv。尝试以下

  • 操作 右键单击​​项目并选择“属性”
  • 转到“调试”选项卡

单击“启动外部程序” 单选按钮。将其指向 devenv.exe 二进制文件。在我的机器上它位于

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\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

  • Right click on the project and select Properties
  • Go to the Debug Tab

Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it's located at

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe

On 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.

迷荒 2025-01-12 06:41:03

@JaredPar 接受的答案在技术上是正确的,但受到以下事实的影响:您需要为每个开发人员重做它,每次您获得代码的新副本,以及任何时候 csproj.user文件被删除。当您这样做时,设置将保存在 csproj.user 文件中。

更好的选择是将设置放入 csproj 文件中,这样它们就不会丢失。不幸的是,Visual Studio 不允许您自动执行此操作,因此您需要手动添加设置。幸运的是,任何项目的设置都是相同的。

右键单击并卸载项目,然后再次右键单击并编辑 csproj 项目文件。在 XML 中,将以下内容添加到第一个 PropertyGroup 中,例如紧接在 TargetFramework 之后。

<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>

这样做有以下优点;

  • 它将它设置为调试和发布
  • 它运行您当前运行的任何版本的 Visual Studio
  • 它已签入源代码管理,因此每个开发人员都不必记住如何执行它:)

正如 @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 the csproj.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 first PropertyGroup, for example right after TargetFramework.

<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>

This has the following advantages;

  • It sets it up for debug and release
  • It runs whatever version of Visual Studio you are currently running
  • It is checked into source control, so every developer doesn't have to remember how to do it :)

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 main csproj file.

薄荷梦 2025-01-12 06:41:03

OutputWindowHelper.OutputString 方法写入“常规”输出窗口窗格(Ctrl Alt o)。我在 .csproj 引用中添加了这一行,以便在 VS 2013 中获取此内容

<Reference Include="Microsoft.VisualStudio.Services.Integration, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

另请参阅 这个答案

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

<Reference Include="Microsoft.VisualStudio.Services.Integration, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

Also see this answer.

三寸金莲 2025-01-12 06:41:03

如果您尝试调试 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文