Вероятно, нет большого исправления, это проблема с самим двигателем T4, IMO.Но если вы пытаетесь уменьшить начальные табуляции / пробелы в выходных данных при сохранении вложенности директив, вы можете сделать следующее:
До
<# for (...) { #>
<# if (...) { #>
SomeText
<# } #>
<# } #>
После
<# for (...) { #>
<# if (...) { #>
SomeText
<# } #>
<# } #>
Например, начните свои директивы со столбца 0, сделайте отступ внутри самой директивы!В дополнение к этому, вы можете обрезать дополнительные строки:
private void TrimExtraneousLineBreaksAfterCommentsFromGeneratedFile(ref string fileText)
{
Regex regex = new Regex(@"(//.+?)(?:\r?\n){2,}");
// Replace multiple coniguous line breaks, after a comment, with a single line break.
fileText = regex.Replace(fileText, "\r\n");
}
private void TrimExtraneousLineBreaksFromGeneratedFile(ref string fileText)
{
Regex regex = new Regex(@"\r?\n(?:\s*?\r?\n)+");
// Replace multiple coniguous line breaks with 2 line breaks.
fileText = regex.Replace(fileText, "\r\n\r\n");
// Remove spaces/line breaks from the file.
fileText = fileText.Trim();
}
YMMV