On Monday I've finally installed the VS 2008 on my system. I put the installation DVD in, choose custom install, pressed run and went to lunch. After I returned, my computer was one VS 2008 richer. And this is where the fun started. We use command line MSBuild and when I fired up the Visual Studio 2008 Command Prompt I got this:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
\Utilities\Bin\x86";C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\
ATI Control Panel;C:\Program Files\IDM Computer Solutions\UltraEdit-32;C:\Program Files\Microsoft SQL Server\8
0\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Too
ls\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Bin
n\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Fi
les\QuickTime\QTSystem\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files\Microsoft SQL Server\100\T
ools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsof
t SQL Server\100\DTS\Binn\;"
was unexpected at this time.
C:\Program Files\Microsoft Visual Studio 9.0\VC>
Running msbuild /? resulted in this:
C:\Program Files\Microsoft Visual Studio 9.0\VC>msbuild /?
'msbuild' is not recognized as an internal or external command,
operable program or batch file.
The same thing happened if I tried csc.exe. To make matters more interesting one other coworker got the same problem while two others had no problems at all.
My first thought was to add MsBuild path to the PATH system environment variable but that proved to be futile. Let us turn to Google then. There were some results that proved useless until I found a link to MSDN forums post. And of course because Murphy works his law like a magic the MSDN forums were down for maintenance.
Ok... let's dig into those darn *.bat files then. The first is %comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86 which starts the Visual Studio 2008 Command Prompt from Start->Program files->\Microsoft Visual Studio 2008->Visual Studio Tools. Looking at the contents of vcvarsall.bat we can see that x86 parameter runs this: call "%~dp0bin\vcvars32.bat"
The file that is called is located at C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat and it only contains one line which is "%VS90COMNTOOLS%vsvars32.bat". This points us to C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat which is broken. This is the broken part:
@if not "%WindowsSdkDir%" == "" (
set "PATH=%WindowsSdkDir%bin;%PATH%"
set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
set "LIB=%WindowsSdkDir%lib;%LIB%"
)
Have you spotted it yet? Probably not.
The problem lies in the ( and ) of the if condition. For explanation let's look at my PATH system environment variable:
"C:\Program Files\Microsoft DirectX SDK (June 2006)\Utilities\Bin\x86";C:\WINDOWS\system32;C:\WINDOWS;C:\WINDO
WS\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\IDM Computer Solutions\U
ltraEdit-32;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools
\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\
;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual St
udio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files\QuickTime\QTSystem\;C:\WINDOWS\system32\WindowsPowerShe
ll\v1.0;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft S
QL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;
Because I have "C:\Program Files\Microsoft DirectX SDK (June 2006)\Utilities\Bin\x86" in my PATH system environment variable the expression
@if not "%WindowsSdkDir%" == "" (
set "PATH=%WindowsSdkDir%bin;%PATH%"
gets terminated by the %PATH%'s " ... June 2006)... " closing ) which results in the weird message that I got when I started up the Visual Studio 2008 Command Prompt
This leaves us with two solutions of the problem:
1. Remove any path that has ( or ) from your PATH system environment variable. This is what I did.
2. Rewrite the If to use goto like this:
@if "%WindowsSdkDir%" == "" goto SkipSDKVariableSet
@set "PATH=%WindowsSdkDir%bin;%PATH%"
@set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
@set "LIB=%WindowsSdkDir%lib;%LIB%"
:SkipSDKVariableSet
The problem with this is that any upgrades can overwrite this so you have to remember and reapply this change.
Hopefully Microsoft will fix this real soon as I see this as a major bug that has to be hacked in an ugly way.
Also note that there is a similar known problem when you install windows SDK after you install VS 2008. A solution to it is described here.