Powershell File Watcher Not Picking Up File Changes Made in Visual Studio

只愿长相守 提交于 2019-12-11 11:51:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!