4

我对 Visual Studio 2010 中的构建后事件有疑问。我有一个 MVC3 项目,我想要一个在当前 chrome 选项卡上刷新的构建后事件。这可能吗?我所拥有的是一个带有此代码的 vb 文件:

 set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.AppActivate "Google Chrome"
 WScript.Sleep 150
 WshShell.SendKeys "{f5}"

在 vs2010 的构建后事件命令行中,我有:

cscript c:\test.vbs

但这不会刷新页面,只会将焦点放在 chrome 上,但即便如此,如果我在焦点后按键盘上的 f5,则 chrome 根本不会刷新。我希望你能帮助我,谢谢!

4

1 回答 1

0

以防万一您在 8 年后仍在寻找解决方案。

就我而言,我想在构建解决方案后刷新我的网站,因为我的构建后事件会将文件复制到我的网站文件夹。我用这个 AutoHotkey 脚本实现了它:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

if WinExist("ahk_exe chrome.exe")
    WinActivate, ahk_exe chrome.exe
    Send {F5}

它最大化我的 chrome 窗口并发送 F5 以刷新屏幕。

当我安装 AutoHotkey 时,我选中了安装在可执行文件中编译脚本的工具的选项,我将其命名为 RefreshSite.exe。这是通过右键单击我的脚本并单击编译脚本来完成的

最后,我的后期构建事件是:

xcopy "MySource" "MyDesination" /s /y
start "" "C:\Projets\AutoHotkey Scripts\RefreshSite.exe"

此解决方案并不完美,如果您的网站位于另一个选项卡中,则会刷新错误的选项卡。它可能可以改进,但对我来说已经足够了。

于 2019-05-03T19:52:04.173 回答