可能有一些与命令行集成的选项不了解 Visual Studio。
红宝石/守卫方式
昨晚我在玩Guard gem。您基本上安装了 Guard 和Guard rake 插件。
gem install guard
gem install guard-rake
您可以创建一个 Guard “模板”,其中Guardfile
包含一个普通的 Rake 任务
guard init rake
例如,您可以对其进行编辑以查看.cs
目录中的文件source
。(和
guard 'rake', :task => 'default', :run_on_start => false do
watch(%r{^source/.+\.cs$})
end
然后启动Guard
guard
您可能需要使用-i
关闭此“交互”模式,这可能会在 Windows 上产生错误!
guard -i
Guard 像一个小型本地服务器一样运行,显示日志
12:07:08 - INFO - Guard uses TerminalTitle to send notifications.
12:07:08 - INFO - Starting guard-rake default
12:07:08 - INFO - Guard is now watching at 'D:/temp'
[1] guard(main)>
如果您强制更改文件(我将转到touch
我在测试目录中设置的假文件),您将获得 rake 任务的输出!
12:07:08 - INFO - Guard uses TerminalTitle to send notifications.
12:07:08 - INFO - Starting guard-rake default
12:07:08 - INFO - Guard is now watching at 'D:/temp'
12:07:54 - INFO - running default
building!...
[1] guard(main)>
PowerShell 方式
没有什么花哨的东西可以包含文件系统轮询触发的操作,但这并不意味着您不能构建自己的!我写了一个.\guard.ps1
位于我的解决方案根目录中的文件。它有一个FileSystemWatcher
并等待循环中的变化。
$here = Split-Path $MyInvocation.MyCommand.Definition
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "$here\source"
$watcher.IncludeSubdirectories = $true
while($true) {
# timeout here lets the console process kill commands and such
$result = $watcher.WaitForChanged('All', 3000)
if($result.TimedOut) {
continue
}
# this is where you'd put your rake command
Write-Host "$($result.ChangeType):: $($result.Name)"
# and a delay here is good for the CPU :)
Start-Sleep -Seconds 3
}
当您touch
或创建 ( New-Item <name> -Type File
) 文件时,您可以看到它正在工作和打印。但是,我们也可以非常简单地执行 rake
rake
PowerShell 将继续并将其作为本机命令执行。你可以花点心思让这个脚本看起来和感觉更像 Guard(好吧,不是更多,而是一点点!)
param(
[string] $path = (Split-Path $MyInvocation.MyCommand.Definition),
[string] $task = 'default'
)
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $path
$watcher.IncludeSubdirectories = $true
while($true) {
$result = $watcher.WaitForChanged('All', 3000)
if($result.TimedOut) {
continue
}
rake $task
Start-Sleep -Seconds 3
}
你会像这样执行它
.\guard.ps1 -Path "$pwd\source" -Task 'build'