包含在 T4 模板中只能使用一次
include in T4 templates only works once
我在 C# 中的 T4 模板中有一个 include 指令:
<#@ include file="styles.css" #>
styles.css 中的文本已正确包含。但只是第一次。如果我在 styles.css 文件和 rebuild/rerun 应用程序中进行更改,则会包含旧版本(就好像它来自缓存或类似的东西一样)。
styles.css 中的更改仅包括在内,如果我删除 include 指令,则构建并插入该行。然后它开始工作......直到在 styles.css
中进行下一次更改
根据 include 指令的 docs,有一个名为 "once" 的可选参数,默认为 "true"。来自文档:
Use once="true" to ensure that a template is included only once, even
if it’s invoked from more than one other include file.
This feature
makes it easy to build up a library of reusable T4 snippets that you
can include at will without worrying that some other snippet has
already included them. For example, suppose you have a library of
very fine-grained snippets that deal with template processing and C#
generation. In turn, these are used by some more task-specific
utilities such as generating exceptions, which you can then use from
any more application-specific template. If you draw the dependency
graph, you see that some snippets would be included several times. But
the once parameter prevents the subsequent inclusions.
我的猜测是将此设置为 false 将允许每次处理您的 css 文件。
我有一个 "solution" 的问题:
模板代码仅在模板本身发生更改时重建。无法识别外部静态文件中的更改。因此,模板的解析必须在通过上下文菜单更改后手动启动 "Run Custom Tool".
我在 C# 中的 T4 模板中有一个 include 指令:
<#@ include file="styles.css" #>
styles.css 中的文本已正确包含。但只是第一次。如果我在 styles.css 文件和 rebuild/rerun 应用程序中进行更改,则会包含旧版本(就好像它来自缓存或类似的东西一样)。 styles.css 中的更改仅包括在内,如果我删除 include 指令,则构建并插入该行。然后它开始工作......直到在 styles.css
中进行下一次更改根据 include 指令的 docs,有一个名为 "once" 的可选参数,默认为 "true"。来自文档:
Use once="true" to ensure that a template is included only once, even if it’s invoked from more than one other include file.
This feature makes it easy to build up a library of reusable T4 snippets that you can include at will without worrying that some other snippet has already included them. For example, suppose you have a library of very fine-grained snippets that deal with template processing and C# generation. In turn, these are used by some more task-specific utilities such as generating exceptions, which you can then use from any more application-specific template. If you draw the dependency graph, you see that some snippets would be included several times. But the once parameter prevents the subsequent inclusions.
我的猜测是将此设置为 false 将允许每次处理您的 css 文件。
我有一个 "solution" 的问题:
模板代码仅在模板本身发生更改时重建。无法识别外部静态文件中的更改。因此,模板的解析必须在通过上下文菜单更改后手动启动 "Run Custom Tool".