27

I have several classes in a project which need to only be in certain builds of the application which are currently not ready for release or debug.

To prevent these classes from being used, I want to set around them this:

#if USE_MYCLASS
// Code here...
#endif

Unfortunately, I don't know how to setup a project-wide #define.

Is there functionality in Visual Studio to set project-wide definitions?

If there is, though I don't need it right now, is there a functionality to set solution-wide definitions?

If there is no functionality for such (seeing as C# does not have include files, I suppose it's possible), is there any method or plugin of doing this functionality without using the command line compiler and /D?

R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
Brett Allen
  • 5,297
  • 5
  • 32
  • 62

1 Answers1

43

You can do that in the project properties, but not in source code.

Project Properties => Build => Conditional compilation symbols

You can specify whichever symbols you need (space delimited, but IIRC is is quite forgiving). Note that DEBUG and TRACE can also be toggled with a checkbox.

I have some projects with multiple "release" build configurations, with different symbols in each (for building 2.0 vs 3.0 vs 3.5 versions - see <DefineConstants> here)

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 1
    Right in front of my face! I never knew that's what that was for, or how to use it, thanks! – Brett Allen Jan 03 '10 at 19:31
  • 3
    "You can do that in the project properties, but not in source code." That is actually quite unpleasant limitation. Being able to do this in code is important for the sake of convenience and visibility. – Radim Cernej Aug 29 '17 at 23:12