本文介绍了Visual Studio-运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不离开Visual Studio的情况下轻松运行批处理文件.批处理文件并不总是相同的,它们会根据我使用的解决方案而变化.

I would like to easily run a batch file without leaving Visual Studio. The batch files are not always the same, they change depending on the solution I'm working with.

我知道您可以在Visual Studio的工具"部分(在外部工具"下)中创建自定义快捷方式.

I know you can create custom shortcuts in the Tools section of Visual Studio (Under External Tools).

我的解决方案具有各种脚本/批处理文件,我希望有一种方法可以在解决方案文件夹或其他特定于解决方案的地方下创建快捷方式.

My solutions have various scripts/batch files and I wish there was a way to create shortcuts under a solution folder or some other place that is solution specific.

我可以创建脚本,但是似乎没有运行脚本的方法.我不希望每次要运行脚本时都必须打开Windows资源管理器.

I can create the scripts but there doesn't seem to be a way to run the script. I don't like having to open Windows Explorer each time I want to run a script.

也许是一个外接程序,它将使用解决方案资源管理器中的选定文件启动进程?还是类似的东西?

Perhaps an add-in that would start a process with the selected file in the solution explorer? Or something similar?

推荐答案

最好的方法是编写一个外部工具,然后您可以根据当前加载的解决方案传递参数.

The best way to proceed is to write an external tool, and then you can pass in parameters based on your current solution that is loaded.

有许多项目和解决方案特定的变量可以传递给外部工具.打开外部工具"对话框,然后在列表框中选择您的工具.您将看到外部工具的标题,以及指向您要调用的脚本或批处理脚本的命令.参数编辑框旁边有一个按钮,旁边有一个箭头.单击箭头,您将看到一个很大的变量或参数列表,您可以将其传递给外部工具.

There are many project and solution specific variables you can pass to your external tool.Open up the 'External Tools' dialog, and select your tool in the list box.You will see the title of your external tool, as well as the command that points to the script or batch script you want to call.The arguments edit box has a button next to it with an arrow next to it. Click the arrow and you will see a big list of variables, or parameters, you can pass to your external tool.

因此,例如,您可以使用以下内容:

So, for instance you can use the following:

$(ProjectDir)-您正在处理的项目的完整路径目录.例如"C:\ builds \ myproject"

$(ProjectDir) - The full path directory of the project you are working on.for instance "C:\builds\myproject"

$(ProjectPath)-您正在使用的vcproj的完整路径名.例如"C:\ builds \ myproject \ foo.vcproj"

$(ProjectPath) - The full path name of the vcproj you are working on.for instance "C:\builds\myproject\foo.vcproj"

$(ProjectName)-项目的名称.例如"foo"

$(ProjectName) - The name of the project.for instance "foo"

$(SolutionDir)-当前正在加载的解决方案的完整路径目录.例如"C:\ builds \ mysolution"

$(SolutionDir) - The full path directory of the solution that is currently loaded.for instance "C:\builds\mysolution"

等...

这篇关于Visual Studio-运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:41