TFS MSBuild: $(ProjectDir) blank or random

msbuildtfs

I have a vcproj file that includes a simple pre-build event along the lines of:

Helpertask.exe $(ProjectDir)

This works fine on developer PCs, but when the solution is built on our TFS 2008 build server under MSBuild, $(ProjectDir) is either blank or points to an unrelated folder on the server!

So far the best workaround I have managed is to hard code the developer and server paths instead:

if exist C:\DeveloperCode\MyProject   HelperTask.exe C:\DeveloperCode\MyProject
if exist D:\BuildServerCode\MyProject HelperTask.exe D:\BuildServerCode\MyProject

This hack works in post-build steps but it doesn't work for a pre-build step (the Pre-build task now does nothing at all under MSBuild!)

Do you have any ideas for a fix or workaround? I have very little hair left!

Best Answer

$(MSBuildProjectDirectory) worked for me

Related Topic