I'm not sure how to do this. I have a batch s开发者_开发知识库cript 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?
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:
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
精彩评论