如何在 Visual Studio 中执行自定义文件特定命令/任务? [英] How to execute custom file specific command / task in Visual Studio?

查看:44
本文介绍了如何在 Visual Studio 中执行自定义文件特定命令/任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够为 VisualStudio 解决方案定义自定义命令/任务/宏.然后我想对 Solution Explorer 中选择的文件执行该命令.

有几种方法可以执行对我来说很好的命令:

a) 在 Solution Explorer 中右键单击文件并从上下文菜单中选择命令(我的最爱)

b) 在 Solution Explorer 中选择一个文件.然后单击工具栏上的按钮.然后该命令会以某种方式从 Solution Explorer 中检索选定的文件.

c) 在 Solution Explorer 中选择一个文件.然后从 Task Runner Explorer 启动一个任务.执行的任务会以某种方式从解决方案资源管理器"中检索所选文件

我尝试使用 VisualStudio 扩展 VsCommandBuddy.但是,它不支持特定于文件的命令,请参阅

2.将外部命令作为入口添加到解决方案资源管理器的上下文菜单中

  • 工具=>自定义=>命令

  • 选择上下文菜单:项目和解决方案上下文菜单 |项目

  • 添加命令...=>工具=>外部命令 1

运行命令

为解决方案资源管理器中的项目使用新的上下文菜单条目

停止命令

为了取消/停止外部命令,您还可以使用解决方案资源管理器的上下文菜单.如果命令的原始名称为Test with Karma",则标题将修改为(Stop) Test with Karma";只要命令正在运行.=>选择该条目以停止命令.

导出设置

很遗憾,这些设置无法与解决方案 (?) 一起存储.但是,可以导出这些设置.然后同事可以导入它们:

  • 工具=>导入和导出设置...=>下一步

  • 常规设置=>外部工具列表和

  • 常规设置=>菜单和命令栏自定义

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 Solution Explorer.

There are several possibilities to execute the command that would be fine for me:

a) Right click on the file in the Solution Explorer and choose the command from the context menu (my favorite)

b) Select a file in the Solution Explorer. Then click on a button on a tool bar. The command would then somehow retrieve the selected file from the Solution Explorer.

c) Select a file in the Solution Explorer. Then start a task from the Task Runner Explorer. The executed task would somehow retrive the selected file from the 'Solution Explorer'

I tried to use the VisualStudio extension VsCommandBuddy. However, it does not support file specific commands, see

https://github.com/PaulHuizer/VsCommandBuddy/issues/21

I also tried to use a Grunt or Gulp task that can be started from the Task Runner Explorer. However, I don't know how I can pass/access the file that is currently selected in the Solution Explorer.

https://blogs.msdn.microsoft.com/webdev/2016/01/06/task-runners-in-visual-studio-2015/

=> Is there a VisualStudio extension that easily allows to define custom commands for files?

=> How can I pass/access the file that is selected in the SolutionExplorer in script files (e.g. Gulp, Grunt, Webpack)?

=> Any other comfortable work flow that you would recommend?

It would be possible to write my own VisualStudio extension. But I guess that someone else already knows a solution for this.

解决方案

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

这篇关于如何在 Visual Studio 中执行自定义文件特定命令/任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆