批处理脚本 - 如果成功,将 msbuild 输出转储到特定文件而不是控制台窗口?

发布于 2024-11-27 03:17:55 字数 537 浏览 1 评论 0原文

我不知道该怎么做。我有一个批处理脚本文件,用于执行多个 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

那么,我该如何:

  1. 将 msbuild 输出转储到日志文件?
  2. 捕获不成功的构建并转到错误标签?

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:

  1. Dump the msbuild output to a log file?
  2. Catch unsuccessful builds and go to the error label?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拍不死你 2024-12-04 03:17:55

添加 /fileLogger 命令行开关会导致 MSBuild 将构建输出写入当前目录中的文件 msbuild.log,而 /noconsolelogger 开关导致 MSBuild 不再写入标准输出。可以使用 /flp 开关设置文件名,如下例所示:

msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=buildlog.txt

请参阅 MSBuild 命令行参考 了解详细信息。

关于你的第二个问题;如果构建失败,MSBuild 将返回非零退出代码,可以照常处理:

msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=SharedLibraries.log
if not errorlevel 0 goto ERROR

msbuild "Myapp.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=Myapp.txt
if not errorlevel 0 goto ERROR

:ERROR

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 /flpswitch as in the following example:

msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=buildlog.txt

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:

msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=SharedLibraries.log
if not errorlevel 0 goto ERROR

msbuild "Myapp.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=Myapp.txt
if not errorlevel 0 goto ERROR

:ERROR
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文