There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Controlling tabs in generated code
Currently, when working with a toolkit project various files are created and some files are continuously re-generated in a toolkit project, and in the toolkit.automation project.
For the sake of this discussion we will make a distinction between T4 templates that are generated once (ever) and refer to these as "one-gen" (i.e. one-shot). T4 templates that are continuous regenerated throughout the lifecycle of the toolkit project
are called "cont-gen".
For example, several "one-gen" files are created when the project is created, but the interface layer code "cont-gen" is regenerated whenever the project is built.
All T4 generated files will contain leading tabs or spaces, that is initially pre-determined by the templates in the authoring toolkit.
However, a VS user can determine whether to use TABS or SPACES in the Options of VS.
(i.e. Tools | Options | Text Editor | <language> | Tabs [Insert Spaces | Keep Tabs]).
This option sets the intention for all ocde in the project.
By default in VS, any VSTemplate (Item or Project) that is unfolded into a project in the solution will be reformatted heeding this setting, regarless of whether the template originally contained leading spaces or tabs. VS automatically reformats the whole
document after creating it. This ensures that the current user's setting is honored.
However, T4 generated files are not subject to the same process when generated. Although, perhaps they could be. It is not done today.
Regardless, users of toolkits will expect code artifacts that are generated to also adhere to their settings.
Either: (1) add a post process to the T4 generation that reformats generated documents according to the user's desired leading tabs/spaces settings.
Or (2) ensure that T4 generated documents make use of utilities that insert leading tabs/spaces at generation time. Regardless of whether they are one-gen or cont-gen.
This can be achieved by using and wrapping the PushIndent() and PopIndent() methods provided by the T4 runtime, and using the currently selected option in the user's setting for the language of text being generated.
However, in order to do this for some T4 files, this makes the T4 overly complex when simple substitutions are all that is required. (e.g. see the guidance document XDOC file!!).