none
List of variables like $(SourceDir)?

    Question

  • I was wondering what variables are known in the Workspace tab for the build definition in TFS 2008 like $(SourceDir) and to what they are translated. I can't seem to be able to find this information on the MSDN Library.

     

    Right now we get error messages for one of our projects that the file path is too long > 260 characters because the $(SourceDir) is resolved to the directory C:\Documents and Settings\TFSBUILD\...

    Friday, January 11, 2008 9:08 AM

Answers

  • As Patrick pointed out, the only variables recognized in the workspace mappings are $(BuildDir) and $(SourceDir)
    hence your attempts to use the other variables in workspace mappings didn't work.

     

    For your build to happen in D:\Builds\<teamproject>\<builddefinition> you need to set BuildDirectory on your Build Agent to D:\Builds\$(BuildDefinitionPath). You do this through the Build Agent Properties dialog. You cannot do this in the
    workspace mappings dialog.

     

    Swaha
    Friday, January 11, 2008 5:58 PM
  • You should be able to safely use any environment variables defined on the machine. For instance, if you want to reference %USERPROFILE%, then you can use $(USERPROFILE). We made the decision to be consistent with the MSBuild syntax of accessing variables, which is why we use the $(...) syntax instead of the surrounding % signs.

     

    The reason your build directory expands like it does is because of the following:

     

    A build directory is defined on the build agent that is running the build. By default this will be $(Temp)\$(BuildDefinitionPath), which expands to %TEMP%\<Team Project>\<Build Definition>. You can make this much shorter by using something like $(Temp)\$(BuildDefinitionId), which will expand to something like %TEMP%\22. This dialog supports the following list:

     

    Environment Variables - any environment variable that is defined for the user or the system

    $(BuildDefinitionId) - a 32-bit identifier for a definition that uniquely identifies it for the Team Foundation Server

    $(BuildDefinitionPath) - a path of the form <Team Project>\<Definition Name>

     

    For the workspace mapping dialog you can only use two variables to help with expansion:

     

    $(BuildDir) - Expands to BuildAgent.BuildDirectory

    $(SourceDir) - Expands to $(BuildDir)\Sources by default

     

    The directory "Sources" is not hard-coded and may be changed by modifying the TfsBuildService.exe.config file on the build agent. If you open that file there will be an application setting called "SourcesSubDirectory". If you need a shorter path you may change this key to something like "s" instead of "Sources". If you made this change then the $(SourceDir) variable would expand to $(BuildDir)\s.

     

    I hope this helps!

     

    Patrick

     

    Friday, January 11, 2008 3:27 PM

All replies

  • You should be able to safely use any environment variables defined on the machine. For instance, if you want to reference %USERPROFILE%, then you can use $(USERPROFILE). We made the decision to be consistent with the MSBuild syntax of accessing variables, which is why we use the $(...) syntax instead of the surrounding % signs.

     

    The reason your build directory expands like it does is because of the following:

     

    A build directory is defined on the build agent that is running the build. By default this will be $(Temp)\$(BuildDefinitionPath), which expands to %TEMP%\<Team Project>\<Build Definition>. You can make this much shorter by using something like $(Temp)\$(BuildDefinitionId), which will expand to something like %TEMP%\22. This dialog supports the following list:

     

    Environment Variables - any environment variable that is defined for the user or the system

    $(BuildDefinitionId) - a 32-bit identifier for a definition that uniquely identifies it for the Team Foundation Server

    $(BuildDefinitionPath) - a path of the form <Team Project>\<Definition Name>

     

    For the workspace mapping dialog you can only use two variables to help with expansion:

     

    $(BuildDir) - Expands to BuildAgent.BuildDirectory

    $(SourceDir) - Expands to $(BuildDir)\Sources by default

     

    The directory "Sources" is not hard-coded and may be changed by modifying the TfsBuildService.exe.config file on the build agent. If you open that file there will be an application setting called "SourcesSubDirectory". If you need a shorter path you may change this key to something like "s" instead of "Sources". If you made this change then the $(SourceDir) variable would expand to $(BuildDir)\s.

     

    I hope this helps!

     

    Patrick

     

    Friday, January 11, 2008 3:27 PM
  • Hello Patrick

     

    Thank you for your reply. I have tried to define in my workspace mapping the folder D:\Builds\$(BuildDefinitionID)\... but that does not work. I have also created the environment variable BuildDirectory that points to D:\Builds and then in my workspace mapping used $(BuildDirectory)\$(BuildDefinitionID)\... but that does not work either because it still points to

    C:\Documents and Settings\TFSBUILD\Local Settings\Temp\TeamProject\BuildDefinitionName\BuildType\$(BuildDirectory)\$(BuildDefinitionID)\ and when I enter %BuildDirectory% in the Run dialog it correctly opens the D:\Builds\ folder.

     

    I opened a command prompt as TFSBUILD:

     

    Microsoft Windows [Version 5.2.3790]
    (C) Copyright 1985-2003 Microsoft Corp.

    C:\WINDOWS>%builddirectory%
    'D:\Builds' is not recognized as an internal or external command,
    operable program or batch file.

    C:\WINDOWS>

     

    I want to be able to build in D:\Builds\<teamproject>\<builddefinition>\, how can I do that?

     

    Thanks

    Friday, January 11, 2008 5:00 PM
  • As Patrick pointed out, the only variables recognized in the workspace mappings are $(BuildDir) and $(SourceDir)
    hence your attempts to use the other variables in workspace mappings didn't work.

     

    For your build to happen in D:\Builds\<teamproject>\<builddefinition> you need to set BuildDirectory on your Build Agent to D:\Builds\$(BuildDefinitionPath). You do this through the Build Agent Properties dialog. You cannot do this in the
    workspace mappings dialog.

     

    Swaha
    Friday, January 11, 2008 5:58 PM
  • Patrick and Swaha thanks for your help. I got it working now and finally understand how the paths and variables work Smile

     

    Monday, January 14, 2008 9:34 AM
  • I have been fixing some issues with my build and decided to use these $(SourceDir) and $(BuildDir) in my build project, however when I put in the line:

    <Message Text="SourceDir = $(SourceDir), BuildDir = $(BuildDir)" />

    I get back empty strings. Is there a way to make these variable apply within the build project, or are they not available there?

    Thanks for any info!

    Robb

    Thursday, March 17, 2011 7:40 PM