Mark Brown's Blog

TFS, Visual Studio, SQL Server, BizTalk, SharePoint, .Net, and more ...

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

Published Friday, July 28, 2006 5:23 PM by mab

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Josh Einstein said:

Couldn't you just precede the command with a "." so that it doesn't matter if directories end with a trailing slash?

For example, the following works fine at the command prompt:

set somedir=C:\windows\Microsoft.NET\Framework\v2.0.50727
dir %somedir%.\mscorlib.dll
set somedir=C:\windows\Microsoft.NET\Framework\v2.0.50727\
dir %somedir%.\mscorlib.dll
July 28, 2006 9:30 PM
 

Jason Haley said:

July 28, 2006 11:22 PM
 

Jason Haley said:

July 28, 2006 11:25 PM

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker