How to execute custom file specific command / task in Visual Studio?

后端 未结 2 2030
天涯浪人
天涯浪人 2021-01-13 23:40

I would like to be able to define custom commands/task/macro for a VisualStudio solution. Then I would like to execute that command for a file that is selected in the

相关标签:
2条回答
  • 2021-01-14 00:09

    You can use my Visual Commander extension to define a custom command/macro. On how to get the currently selected file in Solution Explorer see In a VS 2015 extension, how can I get the selected object in the Solution Explorer?

    0 讨论(0)
  • 2021-01-14 00:33

    1. Create an external tool command:

    • Tools=>External Tools=>Add
    • Use cmd.exe as Command
    • Use /c as first entry for `Arguments' and then specify the command line command you want to execute, e.g. grunt
    • Use the available variables, e.g. $(SolutionDir), $(ItemPath) (=file path), ... to customize your external command

    2. Add external command as entry to the context menu of the solution explorer

    • Tools=>Customize=>Commands

    • Select Context menu: Project and Solution Context Menu | Item

    • Add Command...=>Tools=>External Command 1

    Run command

    Use the new context menu entry for items in the solution explorer

    Stop command

    In order to cancel/stop an external command, you can also use the context menu of the solution explorer. If the original name of the command is "Test with Karma", the title will be modified to "(Stop) Test with Karma" as long as the command is running. =>Select that entry to stop the command.

    Export settings

    Unfortunately those settings can not be stored with the Solution (?). It is however possible to export those settings. Then a colleague can import them:

    • Tools=> Import and export Settings...=>Next

    • General Settings=> External Tools List and

    • General Settings=> Menu and Command Bar Customizations

    0 讨论(0)
提交回复
热议问题