I’m using T4 templates a lot, but only for text-based files (after all one of the T’s stands for Text).
However, I now have a scenario where it would be beneficial use it on an image – read the image, do something with it, write it back. (I want to avoid msbuild-tasks or postbuild applications if possible because T4 integrates nicely into Visual Studio and source control).
However, even when setting <#@ output extension=".png" encoding="ASCII" #>, the generated file has not the exact bytes in it, presumably because converting a byte into a char or string causes a conversion that changes it.
Is there any way to do that? I don’t want to do File.WriteAllBytes because this then doesn’t nicely work with source control.
I don’t think it’s possible with T4, but you could write your own custom VS file generator without too much effort, see here: Writing a custom tool to generate code for Visual Studio .NET