运行 t4 脚本作为 resx 文件的自定义工具

Run t4 script as custom tool for resx file

我有一个资源文件 MyResource.resx,我想更改 MyResource.Designer.cs 文件的生成方式。

我有一个 t4 脚本,它接受一个 resx 文件作为输入并给我生成的转换,但是,我必须手动 运行 这个 t4 才能工作。

我看到 resx 文件的 "custom tool" 属性 当前指定为 PublicResXFileCodeGenerator,我将其更改为 TextTemplatingFileGenerator,但这只使 [=24] =] 像执行 t4 一样执行 resx。

如何将我的 t4 配置为在资源更改时自动 运行 在我的资源上?

检查一下:AutoRunCustomToolDownload from Visual Studio Gallery

来自自述文件:

After you install the extension, you should see a new Run custom tool on property on each project item. Just edit this property to add the name(s) of the target file(s). That's it!

"target" 文件是您的 .tt 文件

没有什么好的方法可以让 Visual Studio 在资源发生变化时自动转换模板,但 MSDN 确实调用了一个设置,您可以将其添加到项目文件中以在构建时进行转换:

https://msdn.microsoft.com/en-us/library/dd820620.aspx#Regenerating