If you use PowerShell to automatically generate code for your project (e.g. during the build process) and you work in TFS-based code, you need to check out existing files before overwriting them. Otherwise the files are read-only and/or not stored in TFS after code generation.
The PowerShell stub script to handle this situation looks like this (assuming the .ps1 file is also inside a TFS directory):
$scriptdir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $basepath = $scriptdir.Substring(0, $scriptdir.Length - "path\from\tfs-base\to\script".Length)
$scriptdir stores the directory name of the currently executed script. If the script file is stored inside your TFS project, you can calculate the file path to checkout from $scriptdir.
Next, we call TFS checkout, generate code, and check in again:
& .\tf-checkout.cmd $basepath ... Code generation is here ... & .\tf-checkin.cmd $basepath
tf-checkout.cmd needs to set the Visual Studio environment variables (as in Visual Studio Command Prompt) to execute the “tf checkout” command:
@echo off setlocal call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 echo. echo checking out... tf checkout %1path\to\file1.cs tf checkout %1path\to\file2.cs ... endlocal
tf-checkin.cmd looks similar:
@echo off setlocal call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 echo. echo checking in... tf checkin /comment:autogenerated /noprompt %1path\to\file1.cs tf checkin /comment:autogenerated /noprompt %1path\to\file2.cs endlocal
Pingback: Typescript Projects in TFS « devioblog
Pingback: Calling xsd.exe in VS 2013 Build Event | devioblog