tags:

views:

592

answers:

3

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!

+1  A: 

I think the problem is that build server's workspace probably isn't initialized properly.

Gerrie Schenck
The weird thing is that it's an intermittent problem. I saw it a few weeks ago, and again today.Having added "echo $(ProjectDir)" to the build step, it prints out the correct value and has started to work again.Most mysterious.I'm beginning to suspect that it wasn't $(ProjectDir) that was broken, but the pre-build step wasn't being executed (it logs that it is executing the prebuild step, but the build continues past the step without any of the commands in it having executed)
Jason Williams
A: 

I just kept getting problems with this - I tried many different approaches but they all failed in mysterious ways.

Once $(ProjectDir) started behaving properly again, the pre-build step stopped executing the command (I added echo commands above and below it - they were both executed, but the program in between them was not. No errors or output of any kind were generated to indicate why it failed).

I don't know if this is a dodgy server of if MSBuild is having a laugh.

I've given up now. I gave the build server a big kick and have changed tack: We now run this tool offline (manually) and check in the results for the build server to use. So much for an automated build :-( If only MSBuild would run solutions in the same way as Visual Studio does - it's maddening that it sets up the environment completely differently (different paths coming out of the solution variables, ouptus redirected into different folders so you can't find them where they're supposed to be, etc)

Jason Williams
+1  A: 

I think your problem may be related to how items are initalized. An items include attribute is evaluated at the begining of a build. So if you depend on files that are created in the build process you must declare these as dynamic items. Dynamic items are those defined inside of a target, or by using the CreateItem task. I've detailed this on my blog MSBuild: Item and Property Evaluation.

Sayed Ibrahim Hashimi
Thanks Sayed. The problem was not that we were creating new files, but just that the program to create them was not even being executed. At one point, $(ProjectDir) was completely wrong, but this must have been something configured incorrectly as the problem disappeared as I fiddled with the project. Having wasted the best part of a day trying to get this simple thing to work I gave up and removed the code generation step from our build - it is now just a manual step the developer has to do whenever he changes the source files (a rare occurence anyway).
Jason Williams