Search code examples
c++visual-studio-2015visual-studio-2017visual-studio-debuggingnatvis

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


I am working with a solution that includes a .natvis in its tree. The workflow requires that I often start debug sessions of various solution's executables using devenv.exe's /DebugExe switch. But when started this way, the .natvis file isn't used by debugger.

I have tried to use /Command switch with Add Existing Item command, but it looks like since the debugged .exe isn't a proper solution or project, it's impossible to add anything to it (at least I have failed).

So the question is: is there a method to use the .natvis placed in an arbitrary path (not in user's profile where VisualStudio would automatically use it) in /DebugExe sessions?


Solution

  • You could use /NATVIS:filename to add your .native file to the .pdb file. It will embed the debugger visualizations defined in the Natvis file filename into the PDB file generated by LINK.

    In addition, you could refer to the Deploying .natvis files part in the link Jack provided. We also could add the .natvis file to user directory or to a system directory. The order in which .natvis files are evaluated is as follows:

    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.