gitpowershelltfstfsbuild

Team Foundation Server Build Files LastWriteTime is Set to Today's Datetime Instead of the Actual LastWriteTime


I am trying to package only files that have been changed in the last 2 minutes using the built-in Team Foundation Server (TFS) build functionality from a git repository on the same TFS server.

I have written a PowerShell script to remove all old files that have a LastWriteTime older than 2 minutes:

# Get the current working directory
$currentDirectory = Get-Location

# Append the target directory to the current working directory
$targetDirectory = Join-Path $currentDirectory "CFM Reporting Project\SSRS\Reports"

# Get all files in the target directory and its subdirectories
Get-ChildItem -Recurse $targetDirectory | 
Where-Object {$_.LastWriteTime -lt (Get-Date).AddMinutes(-2)} | 
Remove-Item -Recurse -Force

# List all in target directory and its subdirectories
Get-ChildItem -Recurse $targetDirectory | Format-List -Property FullName,CreationTime,LastWriteTime,CheckinDate -Force  

I have ensured the build definition sets the Clean option to false.

TFS Build Definition

However, when building, no files are deleted because their LastWriteTimes are ALL the datetime at which the build started:

TFS build logs - folders

Here are further logs which show files since the above screenshot only shows folders: TFS build logs - files

I've used these sources for guidance and exploration of ideas:

Extra information

Can anyone give advice om how to package only the reports with changes in the last 2 minutes, especially since the LastWriteTime does is not working correctly.


Solution

  • The eventual solution was to use a PowerShell script to work out which files were edited in the last commit using git log as follows:

    $modifiedFiles = git log -1 main --name-only --pretty=format: