开发者

How to programmatically control the Build Action of the new files generated from a T4?

开发者 https://www.devze.com 2023-03-25 01:50 出处:网络
The question is: is there a way to have a setting in the *.tt file so that the generated files are set to a specified Build Action?

The question is: is there a way to have a setting in the *.tt file so that the generated files are set to a specified Build Action?

The thing is I am generating code using a template, but it only meant to be a starting point, eliminating a lot of typing. I do not want anyone to use the code(generated classes) as is, nor I want it to clutter the namespace. Currently, I have to manually set th开发者_运维问答e Build Action to None every time a new file being added by the template - I would like to automate it.

Thank you!


A very simple workaround is to wrap the generated code into an #if statement:

#if GENERATED_CODE
    // my generated code
    // will compile only if the variable GENERATED_CODE is defined
#endif
0

精彩评论

暂无评论...
验证码 换一张
取 消