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

1

7

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 the Build Action to None every time a new file being added by the template - I would like to automate it.

Thank you!

Bassinet answered 4/8, 2011 at 14:37 Comment(1)
Here are some previous solutions: #1647080Sector
M
1

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
Madness answered 30/5, 2017 at 8:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.