Mladen Prajdić Blog

Blog about stuff and things and stuff. Mostly about SQL server and .Net

Serious Visual Studio 2008 install bug that can break your builds

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.

 

kick it on DotNetKicks.com
 

Legacy Comments


Stephan
2008-06-19
re: Serious Visual Studio 2008 install bug that can break your builds
Thanks for that explanation. Would have taken me a long time to figure that out myself.

Bala
2008-06-20
re: Serious Visual Studio 2008 install bug that can break your builds
Simpler solution without editing vsvars32.bat, is to remove the quotes from "C:\Program Files\Microsoft DirectX SDK (June 2006)\Utilities\Bin\x86" in the Path variable. If you notice that's the only value with quotes in the Path variable. Removing that fixed this issue in our systems.

Mladen
2008-06-20
re: Serious Visual Studio 2008 install bug that can break your builds
yes as i said in point 1) you can do this too. and that's what i ended up doing too.

magiser
2008-06-27
re: Serious Visual Studio 2008 install bug that can break your builds
I saw in one of your old post that you implement a control tester for a Janus Control, can you explain me how? would you send me an example? thanks!!

magiser
2008-07-02
re: Serious Visual Studio 2008 install bug that can break your builds
Hi I leave my email at the post about Janus. Thanks!!

Nate
2009-01-22
re: Serious Visual Studio 2008 install bug that can break your builds
As Bala said, the issue is really that your path had illegal chars in it. Double-quotes are not valid in Path. You don't have to remove the whole section of your path as you said in Point 1, but rather just remove the double-quotes as Bala said. The real bug is in the DirectX SDK that (presumably) put the double-quotes in there in the first place.

Ryan
2009-07-09
re: Serious Visual Studio 2008 install bug that can break your builds
Solved a similar issue that I was having. Thanks very much!