问题
I have a powershell process that watches for SQL files (in a database project), and then triggers an action when a file changes. The basic setup is below.
$global:SQLFileWatcher = New-Object IO.FileSystemWatcher $rootFolder, $sqlFilter -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'LastWrite'
}
$onSqlCreated = Register-ObjectEvent $global:SQLFileWatcher Changed -SourceIdentifier SqlFileChanged -Action {
#Only called when a new file is added to DB project
Write-Host "HERE"
}
When making changes an existing file already created in Visual Studio Database Project, it's not triggering the file watcher as if the LastWrite time is not being updated. If I open up Notepad++ and edit, this works fine. Also if I add a new SQL file (to a database project), then it triggers the file watcher event on creation AND any updates on that file, which was the strangest part.
Why doesn't it update the file attributes on an existing file, only on new files? Or, a better question to ask may be: is there a better NotifyFilter
setting to use instead of "LastWrite"?
来源:https://stackoverflow.com/questions/49755816/powershell-file-watcher-not-picking-up-file-changes-made-in-visual-studio