Modify_Manager_Templates - nasa/gunns GitHub Wiki

Modifying Network Manager Templates

These are the T4_Text_Templates that we use in MS Visio to format the network manager C++ class code that gets auto-generated when you export your network drawings. These are the .tt files in:

gunns/gunnshow/GunnShow/GunnShowLibrary/FileIO_Utils/TemplateFiles/FluidManagerHeader.tt,

gunns/gunnshow/GunnShow/GunnShowLibrary/FileIO_Utils/TemplateFiles/FluidManagerSource.tt, etc

A GunnSlinger will almost never have to modify these templates, because we try to design the manager class to be as flexible as possible. But just in case it needs changing, here’s how to do it.

The first thing to remember is:

Modifying the template .tt files requires rebuild of GunnShow.

The .tt files aren’t used directly — rather, some C# code is generated from them, and it is this C# code that actually formats the exported manager. These C# files are in the same folder as the .tt files with the same file names but with extension .cs. To speed up the network export in Visio, we build these .cs files into the GunnShow install, rather than have the .tt files be interpreted into C# classes at run-time. Thus, updates to the .tt files have to be migrated into the .cs files and then GunnShow re-built before exported managers will see the changes.

The GunnShow build is a MS Visual Studio solution, so rebuilding GunnShow requires Visual Studio. See the GunnShow User’s Guide for more information on this. Since you need Visual Studio to rebuild GunnShow, it’s best to edit the .tt files inside Visual Studio, because Visual Studio automatically updates the .cs files from the .tt files every time you edit them.

However, the next thing to remember is:

Editing the .tt files outside of Visual Studio doesn’t automatically update the .cs files.

Visual Studio doesn’t know the .tt files have changed if they’re edited outside of its IDE. This has bit us a lot in the past (thus this wiki page!) — engineer A will make a change to the .tt template outside of Visual Studio and tell engineer B to rebuild GunnShow, but B forgets to manually generate the .cs file, and the GunnShow build that gets installed doesn’t have A’s changes! So:

  • It’s always a good idea to make sure the .cs files have been updated when there are changes to the .tt templates. In Visual Studio, you can force an update by right-clicking on the .tt template in the Solution Explorer and select Run Custom Tool. The picture below shows where the files are in the Solution Explorer.
  • Your SCM tool (git, etc) should also indicate to you that there was a .cs file change corresponding to a .tt template change.

Once you remember these rules, updating the templates is a straightforward process. Follow the link at the top of this page for Microsoft’s documentation on how they work.

⚠️ **GitHub.com Fallback** ⚠️