0

I have a controller that is only built in Debug (using #if DEBUG) that I use to house some test methods that I don't want on the production server.

The problem I'm running into is that using T4MVC I get a derived class based on the controller with overloads of all the methods. As soon as I try to build in Release mode that base class and virtual action methods are no longer present and I get build errors.

Ideally I would like to be able to exclude the controller from T4MVC but I can't see a way to do that in the settings file and the answer to this question: T4MVC How to Exclude Individual Files suggests its not possible.

Anyone know of a way to do it or can think of a good work around?

Community
  • 1
  • 1
Greg Jackman
  • 686
  • 7
  • 9

2 Answers2

3

Use the T4MVC Attribute on your controller

[T4MVC(false)]
public Controller ControllerToIgnore //...

Worked for my purposes (to exclude a specific controller from being generated).

From the T4MVC documentation

TJB
  • 13,367
  • 4
  • 34
  • 46
2

Consider separating your test methods and controllers into a separate project that depends on your production code. This way you would not need to have #if Debug stuff. I'm not sure what is your set up, but you can try using NonActionAttribute that is wrapped inside #if !Debug clause. So your production code would not run the methods as actions on your controllers. But this stinks with the wrong layout of the project.

trailmax
  • 34,305
  • 22
  • 140
  • 234