Passing a preprocessor directive to MSBUILD via the command line instead of #DEFINE in code

I recently wanted to pass a preprocessor directive (as in affecting /define in csc.exe) to MSBUILD on the commandline instead of using #DEFINE/#UNDEF in the source code or modifying the configuration properties in VS.  (After all, isn't that the idea of directives -- change them from the command line and don't mess with the source code?)  Here's how:

Let's say I had in my code:

#if DO_SOMTHING
//do something
#endif

I would call msbuild like this

msbuild /p:DefineConstants=DO_SOMETHING

Beware that msbuild will not rebuild if only the directive changed, so you may also want to add /t:Rebuild

msbuild /p:DefineConstants=DO_SOMETHING /t:Rebuild