如何从 IDE 内部运行 .bat [英] How to run a .bat from inside the IDE
问题描述
我想做的很简单,却找不到方法.
在我的项目中,我有几个 .bat 文件(我知道,我老了)执行一些任务,例如运行 SqlMetal 等.
What I want to do is very simple, yet can't find the way to do it.
In my projects I have several .bat files (I know, I'm old) the perform some tasks like running SqlMetal, etc.
我只想右键单击该文件并选择运行"或其他内容,以便执行 bat.我该怎么做?
I just want to right-click the file and select "run" or something so the bat is executed. How do I do it?
注意:我知道我可以使用工具 -> 外部工具,但这不是我想要的
推荐答案
如果每个项目都有几个与之关联的批处理文件,那么为什么不将它们包含在项目中并添加一个新的外部工具并将其与自定义菜单项链接运行该工具?这将为您提供每个项目中的批处理文件列表以及运行它们的上下文菜单命令.唯一的缺点是它不是特定于文件类型的(它可以让您将任何文件作为批处理文件运行).
If each project has a few batch files associated with it then why not include them in the project and add a new external tool and link it with a custom menu item to run the tool? This will give you a list of batch files in each project and a context menu command to run them. The only downside is that it isn't file type specific (it will let you run any file as a batch file).
这是如何做到的...
创建一个名为运行批处理文件"的外部工具
Create an external tool called "Run batch file"
- 将命令设置为:CMD.EXE
- 将参数设置为:/c "$(ItemPath)"
- 将初始目录设置为:$(ItemDir)
- 选中使用输出窗口"复选框,然后应用以创建命令
- 注意新命令出现在命令列表中的位置.外部命令从分隔条下方的 1 开始编号.#1 通常是创建 GUID"
现在转到工具 -> 自定义并选择命令选项卡.
Now go to Tools -> Customize and select the commands tab.
- 选择上下文菜单单选按钮,然后从下拉列表中选择项目和解决方案上下文菜单 | 项目".
- 现在使用添加命令..."添加新命令
- 在类别列表中选择工具"
- 从命令中选择与您在上面第 5 步中记下的运行批处理文件"自定义命令的位置相对应的外部命令编号".
- 将其移动到列表中的正确位置,添加键盘快捷键等.
- 关闭对话框.
现在右键单击批处理文件,您应该会看到运行批处理文件"菜单项.这将执行批处理文件并在 VS 输出窗口中显示其输出.
Now right click on the batch file and you should see a "Run batch file" menu item. This will execute the batch file and show its output in the VS Output window.
这篇关于如何从 IDE 内部运行 .bat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!