Difference in MSBUILD from command-line versus IDE (paths and backslashes)

Scenario
Have you ever had problems building from command-line using MSBuild when the IDE builds just fine?

Do you have build events that use the Macros or environment variables?

Well then I may have found the issue ...

Reason
When the IDE call msbuild it appears to setup all those envrionment variables such as devenvdir with a trailing backslash like the following

SET devenvdir=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\

If you crank up the Visual Studio Command prompt and check out the environment variable you will find that devenvdir is set WITHOUT the trailing backslash!

Workaround #1
Say you are using devenvdir macro you could modify the batch command to add the following line (just one way of many) to make sure the backslash (\) always exists before your build event commands run:

if not exist "%devenvdir%devenv.exe" set devenvdir=%devenvdir%\
... remaining commands ...

Workaround #2 (better)
Thanks to comments from Josh a more simplified workaround would to just use a "." after the devenvdir variable.  With a "." DOS will only make it relative to the folder regardless if a backslash exists or not.

%devenvdir%.\devenv.exe