在VS2012中发布构建事件..运行批处理文件 [英] Post build event in VS2012..Running a Batch file

查看:141
本文介绍了在VS2012中发布构建事件..运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio的后期生成事件中运行批处理文件。



已引用供参考。



当我发布该行

  xcopy $(ProjectDir)bin $(SolutionDir)Deploy\bin / S在生成后

我获得了预期的结果



我把同一行放在蝙蝠中并尝试调用

  call $(SolutionDir)\Deploy.bat 

 调用 Physical path\deploy.bat 

我对代码1感到兴奋。

我可以在批处理文件中指定宏吗?



谢谢

解决方案

您收到VS错误,因为它返回了一个不为0的退出代码。这不一定意味着存在错误。



返回的错误代码表示没有文件被复制。
这些是Xcopy的返回代码:




  • 退出代码

    • 0文件已复制,没有错误。

    • 1找不到要复制的文件。

    • 2用户按下Ctrl + C终止xcopy。

    • 4各种错误,包括内存或磁盘空间不足,无效的驱动器名称或无效的语法。

    • 5发生磁盘写入错误。




在批处理文件中尝试此代码。使用/ Y,这样您就不必处理任何提示。您可以使用其他操作来处理1的返回码,也可以只返回0。



VS Post Build命令行代码:



CALL $(SolutionDir) Deploy.bat $(ProjectDir)bin $(SolutionDir)Deploy\bin



Deploy.bat文件



Xcopy%1%2 / S / Y



如果错误级别1 @出口0


Am trying to run a Batch file in Post build event in Visual studio.

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

When i post the line

xcopy "$(ProjectDir)bin" "$(SolutionDir)Deploy\bin" /S in postbuild

am getting the expected result

Same line i put in bat and tried calling

call "$(SolutionDir)\Deploy.bat"

or

call "Physical path\deploy.bat"

Am getting excited with code 1. What am i doing wrong here ?

Can i specify macros inside batch file ?

Thanks

解决方案

You are getting a VS error because it returned an exit code that is not 0. This does not necessarily mean there was an error.

The error code returned means that no files were copied. These are the return codes for Xcopy:

  • Exit Code
    • 0 Files were copied without error.
    • 1 No files were found to copy.
    • 2 The user pressed Ctrl+C to terminate xcopy.
    • 4 Various errors including insufficient memory or disk space, an invalid drive name, or invalid syntax.
    • 5 Disk write error occurred.

Try this code in your batch file. Use the /Y so that you will not have to deal with any prompts. You can handle the return code of 1 with another action or just return 0.

VS Post Build command line code:

CALL "$(SolutionDir)"Deploy.bat "$(ProjectDir)bin" "$(SolutionDir)Deploy\bin"

Deploy.bat file

Xcopy %1 %2 /S /Y

If errorlevel 1 @exit 0

这篇关于在VS2012中发布构建事件..运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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