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!

Andrei
  • 4,122
  • 3
  • 22
  • 24
  • Here are some previous solutions: http://stackoverflow.com/questions/1646580/get-visual-studio-to-run-a-t4-template-on-every-build – Mikael Ohlsson Apr 26 '17 at 13:28

1 Answers1

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
Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55