批处理脚本 - 如果成功,将 msbuild 输出转储到特定文件而不是控制台窗口?
我不知道该怎么做。我有一个批处理脚本文件,用于执行多个 msbuild 调用。我不希望 msbuild 输出污染我的命令窗口,而是希望将其转储到日志文件中。我不确定如何执行此操作,但这是到目前为止我的脚本:
@ECHO Building shared libraries ...
msbuild "SharedLibraries.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:: Copy dll files to specific location
@ECHO Building primary application...
msbuild "Myapp.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:ERROR
那么,我该如何:
- 将 msbuild 输出转储到日志文件?
- 捕获不成功的构建并转到错误标签?
I'm not sure how to do this. I have a batch script file I am using to do multiple msbuild calls. I don't want the msbuild output to pollute my command window, but instead I want it to dump into a log file. I'm not sure how to do this, but here's my script so far:
@ECHO Building shared libraries ...
msbuild "SharedLibraries.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:: Copy dll files to specific location
@ECHO Building primary application...
msbuild "Myapp.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:ERROR
So, how do I:
- Dump the msbuild output to a log file?
- Catch unsuccessful builds and go to the error label?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
/fileLogger
命令行开关会导致 MSBuild 将构建输出写入当前目录中的文件 msbuild.log,而/noconsolelogger
开关导致 MSBuild 不再写入标准输出。可以使用/flp
开关设置文件名,如下例所示:请参阅 MSBuild 命令行参考 了解详细信息。
关于你的第二个问题;如果构建失败,MSBuild 将返回非零退出代码,可以照常处理:
Adding the
/fileLogger
command line switch causes MSBuild to write the build output to file msbuild.log in the current directory, while the/noconsolelogger
switch causes MSBuild to no longer write to standard output. The filename can be set using the/flp
switch as in the following example:See MSBuild Command Line Reference for details.
Regarding your second question; MSBuild returns a non-zero exit code if the build failed, which can be processed as usual: