visual-studio 我们可以在 Visual Studio 的后期构建事件命令行中执行 .bat 文件吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1491394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:03:00  来源:igfitidea点击:

Can we execute a .bat file in post build event command line in visual studio?

visual-studiovisual-studio-2008visual-studio-2005build-automation

提问by Piotr Owsiak

Can we execute a .bat file in post build event command line in visual studio?

我们可以在 Visual Studio 的后期构建事件命令行中执行 .bat 文件吗?

回答by Piotr Owsiak

Sure, here's an example:

当然,这是一个例子:

call "$(SolutionDir)scripts\copyifnewer.bat" "$(SolutionDir)libs\RLPL.Services.CertificateValidator.Basic.dll" "$(TargetDir)RLPL.Services.CertificateValidator.Basic.dll"
call "$(SolutionDir)scripts\copyifnewer.bat" "$(SolutionDir)libs\RLPL.Services.CertificateValidator.Common.dll" "$(TargetDir)RLPL.Services.CertificateValidator.Common.dll"

Just be aware of two possible issues you might have:

请注意您可能遇到的两个可能问题:

  1. the enclosing double quotes (see how each part is surrounded by "sign)

  2. if you want to call 2 or more batch files make sure you use callcommand otherwise you'll have a trouble finding why the second bat is not doing its job

  1. 封闭的双引号(看看每个部分是如何被"符号包围的)

  2. 如果您想调用 2 个或更多批处理文件,请确保使用call命令,否则您将无法找到第二个 bat 不工作的原因

回答by Mark Seemann

Yes, by adding a call to it in the post-build event editor.

是的,通过在构建后事件编辑器中添加对它的调用。

If you go to the Properties page for your project, you should select the Build Events tab. You can type in the call to your batch file in the Post-build event command linetext box.

如果您转到项目的“属性”页面,则应选择“构建事件”选项卡。您可以在生成后事件命令行文本框中键入对批处理文件的调用。

If you want to refer to the batch file using the paths included in the project or solution, you can click on the Edit Post-Build...button. This will open the Post-build Event Command Linedialog box.

如果要使用项目或解决方案中包含的路径引用批处理文件,可以单击“编辑后构建...”按钮。这将打开构建后事件命令行对话框。

This dialog box has a Macros >>button that you can click. It will show you all the available Macros that you can use to refer to folders and files within your solution.

此对话框有一个宏 >>按钮,您可以单击该按钮。它将向您显示所有可用的宏,您可以使用这些宏来引用解决方案中的文件夹和文件。

When you select one of those macros, you can use the Insertbutton to insert them into your script.

当您选择这些宏之一时,您可以使用“插入”按钮将它们插入到您的脚本中。

回答by Polyfun

As well as calling a .bat file, you can enter batch commands (i.e., the normal commands available from the Windows console--cmd.exe) directly into the Pre-build/Post-build fields. This may be preferable as it means you do not have to maintain the batch file separately, as all your commands will be part of the project.

除了调用 .bat 文件外,您还可以直接在预构建/后构建字段中输入批处理命令(即 Windows 控制台中可用的普通命令 - cmd.exe)。这可能更可取,因为这意味着您不必单独维护批处理文件,因为您的所有命令都将成为项目的一部分。