Search code examples
tfsbuildsymlink

Creating symlinks in TFS 2010 Build Workflow Template


The scenario is that we are copying files out to our drop folders, but we also want to generate a "Latest" symlink that points to the most recent build of that build definition. I've created "Latest" folders in the past with a delete directory/copy command, but I don't want to eat up the hard drive space or add potentially minutes to the build execution time.

Does anyone know of a way to create symlinks during a build in TFS2010/Team Build 2010? The problem lies entirely in the fact that you have to already be elevated/executing as admin to create a symlink and, from what I can tell, the build does not run elevated/as admin. I've tried running the build service under a user account that is a local administrator and it still doesn't work.

I've listed below the following things I've already tried to do to get this to work, but none of them have worked:

  • Used the InvokeProcess workflow activity to execute various forms of "cmd.exe /c mklink /d ..." directly
  • Used InvokeProcess to execute a batch script that contained the mklink command.
  • Tried using RUNAS [mklink command] (which fails because you are prompted to enter a password manually).
  • Tried using the InvokeProcess activity on a C# command line utility I wrote that runs elevated via the requiresAdmin option in the Application Manifest file. This utility does not prompt for elevation (UAC) AT ALL.

If anyone has any ideas or has already done this, I'd be greatly appreciative of any suggestions presented.


Solution

  • Duat Le's suggestion of turning off UAC solved the problem.

    Here's what needs to be done to get this to work.

    1. UAC needed to be turned off for the account running the build service on the build server.
    2. The account that the build server is running under needs to be a local administrator on the server you are trying to set the symlink up on.
    3. After UAC was turned off, I used an InvokeProcess activity in the workflow, giving it the following values:

      • Arguments:
        "/c mklink /d ""<symlink name>"" ""<directory for symlink to point to>"""

      • FileName: "cmd.exe"

      • WorkingDirectory: "<some dir>"