开发者

Counting warnings from MSBuild task

I have the following msbuild goop :

<MSBuild Projects="$(MySLN)" Targets="Build" />
<!--count all warning and fail if > 20-->
<Exec WorkingDirectory="$(BuildFolder)"
  IgnoreExitCode="true"
  Command="$(POWERSHELL) -command $host.SetShouldExit(([xml](get-content '$(LogsFolder)productbuild-results.xml')).SelectNodes('//warning').count)"
>
  <Output PropertyName="BuildSLNWarningCount" TaskParameter="ExitCode" />
</Exec>

In theory this will count the number of warnings in the log file so I can abort the build if there are too many (>20 in our case).

However, I dont know how to get the MSBuild task to output a log file - seperate from the log file that is produced from the main MSBuild file that 开发者_如何转开发this task is run by. Also, I still need the main log file to contain the full build details as it's used by CCnet.

Is this possible?

Thanks


I would recommend using BuildManager class... The BeginBuild method on the BuildManager allows you to pass in a set of BuildParameters which includes a Loggers property. In the Logger you can capture anything MSBUILD outputs and count etc.


I think your best bet would be writing a custom MSBuild task which does everything you need, and call that in your build script. I blogged an example here. My task has a very different intent from yours, but you should get the main concepts about writing a custom task.

Update: Another posibility is using the Exec task to call MSBuild redirecting its output to a file:

<Exec WorkingDirectory="$(BuildFolder)"
  IgnoreExitCode="true"
  Command="$(MSBuildDirectory)msbuild params > output_file.txt"
>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜