有没有一种方法可以自动将 .natvis 附加到使用 -DebugExe 启动的调试会话?

Is there a method to automatically attach a .natvis to debug session started using -DebugExe?

我正在使用一个在其树中包含 .natvis 的解决方案。工作流程要求我经常使用 devenv.exe 的 /DebugExe switch 启动各种解决方案的可执行文件的调试会话。但是当以这种方式启动时,.natvis 文件不会被调试器使用。

我曾尝试使用 /Command switch with Add Existing Item command,但看起来由于调试的 .exe 不是正确的解决方案或项目,所以不可能向其添加任何内容(至少我失败了)。

所以问题是:是否有一种方法可以在 /DebugExe 会话中使用放置在任意路径(而不是 VisualStudio 会自动使用它的用户配置文件中)的 .natvis?

您可以使用 /NATVIS:filename 将您的 .native 文件添加到 .pdb 文件。它将 Natvis 文件文件名中定义的调试器可视化嵌入到由 LINK.

生成的 PDB 文件

另外,你可以参考link Jack提供的Deploying .natvis files部分。我们还可以将 .natvis 文件添加到用户目录或系统目录。 .natvis 文件的计算顺序如下:

  1. natvis files embedded in a .pdb you are debugging (unless a file of the same name exists in a loaded project)
  2. natvis files that are part of a loaded C++ projects or a top-level solution item. This includes all loaded C++ projects, including class libraries, but it does not include projects of other languages (e.g. you can’t load a .natvis file from a C# project). For executable projects, you should use the solution items to host any .natvis files that are not already present in a .pdb, since there is no C++ project available.
  3. The user-specific natvis directory (%USERPROFILE%\My Documents\Visual Studio 2015\Visualizers
  4. The system-wide Natvis directory (%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers). This is where .natvis files that are installed with Visual Studio are copied. You can add other files to this directory as well if you have administrator permissions.