I’d like to add a new natvis but all the info I’ve found for adding it to Unreal says to either put it in my VS install folder or to manually add it to the solution. Neither of those options work on a team.
Is there a build file option or something that I need to add to have the solution generation pick up the file?
Well this is a year late, but I encountered the same obstacle today and found a solution. If you have the engine built from source, you can modify UnrealBuildTool to injection additional natvis files. I have aspirations of sending a Pull Request for this support, but here’s a rough example:
Location in Unreal 5 source: Line 800 of Source/Programs/UnrealBuildTool/ProjectFiles/VisualStudio/VCProjectFileGenerator.cs
VCSolutionFileContent.AppendLine("\tProjectSection(SolutionItems) = preProject");
// START CHANGE: Add support for user-defined natvis files being added to the VisualStudio solution
/* Previous
VCSolutionFileContent.AppendLine("\t\t{0} = {0}", VisualizersFile.MakeRelativeTo(PrimaryProjectPath));
*/
// New
List<FileReference> AllVisualizerFiles = new List<FileReference>();
List<DirectoryReference> VisitedProjectDirectories = new List<DirectoryReference>();
AllVisualizerFiles.Add(VisualizersFile);
foreach (MSBuildProjectFile CurProject in AllProjectFiles)
{
// Multiple projects exist with the same base dir, so skip if we've already checked this directory for natvis
if (VisitedProjectDirectories.Contains(CurProject.BaseDir))
{
continue;
}
VisitedProjectDirectories.Add(CurProject.BaseDir);
// Only enumerate files if the natvis location exists
DirectoryReference DebuggingDir = DirectoryReference.Combine(CurProject.BaseDir, "Extras", "VisualStudioDebugging");
if (!DirectoryReference.Exists(DebuggingDir))
{
continue;
}
// Iterate the directory for all natvis files
foreach (FileReference VisualizerFile in DirectoryReference.EnumerateFiles(DebuggingDir, "*.natvis"))
{
if (!AllVisualizerFiles.Contains(VisualizerFile))
{
AllVisualizerFiles.Add(VisualizerFile);
}
}
}
// Append each found natvis file (and the Unreal.natvis that always exists) to the solution file
foreach (FileReference VisualizerFile in AllVisualizerFiles)
{
VCSolutionFileContent.AppendLine("\t\t{0} = {0}", VisualizerFile.MakeRelativeTo(PrimaryProjectPath));
}
// END CHANGE: Add support for user-defined natvis files being added to the VisualStudio solution
VCSolutionFileContent.AppendLine("\tEndProjectSection");
You’ll note in that diff that the previous comment block disables the explicit addition of the Unreal.natvis file, and replaces the logic with a enumerator over all “projects” (not the same definition of “.project” files, these are just modules that the build tool refers to as projects) to look for all natvis files.