t4-toolbox

T4 append output to existing file

折月煮酒 提交于 2020-01-02 00:57:08
问题 Is it possible to make a T4 template output to be merged with an existing file? For example, if a T4 template generates localization resource XML files, is it possible to merge them in some existing resource file? 回答1: You can get access to the underlying string builder the the T4 uses thought the GenerationEnvironment property. So by adding something like the following to your T4 you should be able to get a workable solution; <#@ template debug="false" hostspecific="false" language="C#" #> <

T4 Toolbox - Referencing Class in Current Assembly

冷暖自知 提交于 2019-12-21 07:15:57
问题 I am writing a T4 script which reflects over certain classes and provides code generation based on them. The problem is that my script errors out, saying that the classes in my current project cannot be accessed. The script itself resides in the same assembly as the classes I am trying to reference. I've tried referencing the namespace, the file and adding a reference to the current assembly (the project itself) - all to no avail. What am I missing? 回答1: I believe this is what Nicko and uosɐſ

T4 append output to existing file

谁说我不能喝 提交于 2019-12-05 01:16:25
Is it possible to make a T4 template output to be merged with an existing file? For example, if a T4 template generates localization resource XML files, is it possible to merge them in some existing resource file? You can get access to the underlying string builder the the T4 uses thought the GenerationEnvironment property. So by adding something like the following to your T4 you should be able to get a workable solution; <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".txt" #> <#@ Import Namespace="System.IO" #> Line #<#= rand.Next(0, 100).ToString() #>

T4 Toolbox - Referencing Class in Current Assembly

末鹿安然 提交于 2019-12-04 00:17:57
I am writing a T4 script which reflects over certain classes and provides code generation based on them. The problem is that my script errors out, saying that the classes in my current project cannot be accessed. The script itself resides in the same assembly as the classes I am trying to reference. I've tried referencing the namespace, the file and adding a reference to the current assembly (the project itself) - all to no avail. What am I missing? Brian I believe this is what Nicko and uosɐſ are looking for. Just change the "MyAssembly.CodeGeneration" to the name of the project with the T4