如何在Visual Studio中执行自定义文件特定的命令/任务? [英] How to execute custom file specific command / task in Visual Studio?
问题描述
我希望能够为VisualStudio解决方案定义自定义命令/任务/宏。然后,我想对解决方案资源管理器
中选定的文件执行该命令。
执行该命令的几种可能性对我来说很合适:
a)右键单击在解决方案资源管理器
中选择文件并从上下文菜单中选择命令(我最喜欢的)b
$ b b)选择一个文件放在解决方案资源管理器
中。然后点击工具栏上的按钮。然后该命令以某种方式从解决方案资源管理器
中检索选定的文件。
c)在解决方案资源管理器
中选择一个文件。然后从 Task Runner Explorer
开始一个任务。执行的任务会以某种方式从解决方案资源管理器中检索选定的文件。
我尝试使用VisualStudio扩展 VsCommandBuddy
。但是,它不支持文件特定命令,请参阅
添加外部命令作为解决方案资源管理器的上下文菜单的入口
-
工具=>自定义=>命令
li>
-
选择上下文菜单:项目和解决方案上下文菜单| Item
-
添加命令... =>工具=>外部命令1
-
工具=>导入和导出设置... =>下一步
-
常规设置=>外部工具列表和
-
常规设置=>菜单和命令栏自定义
p> - 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 Tools=>Customize=>Commands
Select Context menu: Project and Solution Context Menu | Item
Add Command...=>Tools=>External Command 1
Tools=> Import and export Settings...=>Next
General Settings=> External Tools List and
General Settings=> Menu and Command Bar Customizations
$ b
运行命令
在解决方案资源管理器中使用新的上下文菜单项
停止命令
为了取消/停止外部命令,还可以使用解决方案资源管理器的上下文菜单。如果该命令的原始名称是Test with Karma,则只要该命令正在运行,标题将被修改为(停止)以Karma测试。 =>选择该条目来停止命令。
导出设置
不幸的是,这些设置无法与Solution(?)一起存储。但是可以导出这些设置。然后一个同事可以导入它们:
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.
Create an external tool command:
Add external command as entry to the context menu of the solution explorer
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:
这篇关于如何在Visual Studio中执行自定义文件特定的命令/任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!