TFS MSBuild: $ (ProjectDir) empty or random

I have a vcproj file that includes a simple pre-build event in lines:

Helpertask.exe $(ProjectDir) 

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

So far, the best solution I've dealt with is the complex code of the developer and server path:

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

This hack works in the post- build steps, but it does not work for the pre -build step (the Pre-build task now does nothing in MSBuild!)

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

+4
source share
5 answers

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

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

I don't know if this is a dodgy server if MSBuild is laughing.

Now I have given up. I gave the build server a big blow and changed course: now we run this tool offline (manually) and check the results for the build server. So much for automatic assembly :-( If only MSBuild launched the solutions in the same way as Visual Studio, it is crazy that it sets up the environment in completely different ways (different paths coming out of the solution variables are redirected to different folders ouptus so you cannot find them where they should be, etc.)

0
source

$ (MSBuildProjectDirectory) worked for me

+7
source

I think your problem may be related to how the elements are initialized. Elements that include an attribute are evaluated at the beginning of the assembly. Therefore, if you depend on files created during the build process, you must declare them as dynamic elements. Dynamic elements are those that are defined inside the target, or using the CreateItem task. I described this in detail on my MSBuild blog : evaluating items and properties .

Said Ibrahim Hashimi

My book: Inside Microsoft Build Engine: Using MSBuild and Team Foundation Build

+1
source

I think the problem is that the assembly server workspace is probably not initialized properly.

0
source

I forked an existing project, and $ (ProjectDir) saved the old directory in the newly forked code. But this is because I had some compilation errors. As soon as each project in the solution was compiled without errors, $ (ProjectDir) changed to the correct path.

Carlos A Merighe

0
source

Source: https://habr.com/ru/post/1286126/


All Articles