开发者

Any way to get Visual Studio to save the file before running an external tool?

开发者 https://www.devze.com 2022-12-08 01:19 出处:网络
I\'ve have a couple of external tools set up to run Doxygen for me, either on the currently displayed file, or the currently active project.

I've have a couple of external tools set up to run Doxygen for me, either on the currently displayed file, or the currently active project.

What's annoying is, there doesn't seem to be an option anywhere to save the file before running the tool.

So I'll hammer in some Doxygen block开发者_JAVA技巧s, hit the hotkey to run Doxygen, flip over to Firefox to check the output, and, of course..... it's the previous version.

Sigh.

Any clues on how to get this to work in a nice way?


You could create a VS macro that would save all files first and then your external tools.


I have found a solution to this in VS2013 by using Visual Commander. This gives you back the ability to run macros. You can now create a macro which saves all files and then runs your external tool, eg.

Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
    Implements VisualCommanderExt.ICommand

    Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
        DTE.ExecuteCommand("File.SaveAll")
        DTE.ExecuteCommand("Tools.ExternalCommand6" )
    End Sub
End Class

This macro can now be added to a tool bar or keyboard shortcut instead of running the external tool directly.


Get used to hitting Ctrl+S as often as possible, or even better in VS: Ctrl+Shift+S. :)

(Seriously. I'm so used to do this, Firefox regularly pops up its "Save As" dialog to save this website, because I hit Ctrl+S while typing my answers into SO.)


In case you are using Visual Studio 2012 or later, you don't have macros anymore.

I solved this problem using an AutoHotKey script to fill in that gap.

Here is how I did it:

SetTitleMatchMode, 2       ; Title matches if it contains string

#IfWinActive Visual Studio ; The shortcuts below this line are valid when Visual Studio is active
!s::                       ; Alt+s to activate the external tool
    SendInput ^s           ; Sends Ctrl+s to Visual Studio to save the file
    Sleep, 100
    SendInput ^!+\         ; Actual shortcut that activates the desired external tool
return
#IfWinActive               ; Shortcuts below this line will be global


Use Visual Studio 2005. It automatically saves all files before running external tools.

(I realise that this is not generally going to be helpful, but as I use both 2005 and 2012 this is one of my main annoyances with 2012)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号