Ref: Visual Studio Team Foundation Server 2015: How do i check from within a batch- or Powershell-script for a given file under TFS source control, if a local file is or is not equal to the latest version on the server?
2
votes
1 Answers
4
votes
You can use tf.exe, which comes with Visual Studio. Here are some different options using PowerShell. This could also be written in batch with a few changes.
Assume the following:
# Change directory to the folder containing your file.
Set-Location "D:\MyProjects\Project1\Logic"
# File to evaluate
$file = "Program.cs"
# Using the Visual Studio 2015 Common Tools System Variable to find tf.exe
$tfExe = "$env:VS140COMNTOOLS\..\IDE\TF.exe"
1: Use get /preview
, which will preview if it can get a newer version.
& cmd /c "`"$tfExe`" get $file /preview"
Result if latest:
All files are up to date.
Result if not latest:
D:\MyProjects\Project1\Logic:
Replacing Program.cs
2: Use difference /format:Brief
with status
, which will tell you if there are differences locally, but no pending changes
& cmd /c "`"$tfExe`" difference $file /format:Brief"
& cmd /c "`"$tfExe`" status $file"
Result if latest:
Comparing local to latest: D:\MyProjects\Project1\Logic\Program.cs
There are no pending changes.
Result if not latest:
Comparing local to latest: D:\MyProjects\Project1\Logic\Program.cs
Program.cs: files differ
There are no pending changes.
3: Use info
, which will show the local changeset and the server changeset, and you can see if they're different.
& cmd /c "`"$tfExe`" info $file"
Result:
Local information:
Local path : D:\MyProjects\Project1\Logic\Program.cs
Server path: $/MyProjects/Project1/Logic/Program.cs
Changeset : 2842
Change : none
Type : file
Server information:
Server path : $/MyProjects/Project1/Logic/Program.cs
Changeset : 2845
Deletion ID : 0
Lock : none
Lock owner :
Last modified: Friday, December 15, 2017 4:32:57 PM
Type : file
File type : utf-8
Size : 2835
Info/Properties Documentation Link
There is also LocalVersions, which will tell you the local changeset of your file, and History which will show all changesets of the file.