如何更改MSBuild任务的详细程度? [英] How to change verbosity of the MSBuild task?

查看:179
本文介绍了如何更改MSBuild任务的详细程度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于从命令行调用的msbuild项目和从项目内部的MSBuild任务调用的项目,我希望具有不同的详细程度.例如:

I'd like to have a different verbosity for the msbuild project invoked from the commandline, and those invoked by the MSBuild task from within the project. For example:

在my.proj内部:

Inside my.proj:

<Target Name=Foo>
  <MSBuild Projects="a.csproj;b.csproj;c.csproj"/>
</Target>

在命令行上:

msbuild /v:d my.proj

现在,当MSBuild任务生成.csproj文件时,它也会以详细的详细程度进行处理.但是,我想以最小的冗长程度来构建它.

now when the MSBuild task builds the .csproj files, it does it with detailed verbosity as well. However I'd want to build it with minimal verbosity.

我知道可以像这样手动调用msbuild:

I know it is possible to invoke msbuild manually like so:

<Target Name=Foo>
  <Exec Command="msbuild /v:m a.csproj"/>
  <Exec Command="msbuild /v:m b.csproj"/>
  <Exec Command="msbuild /v:m c.csproj"/>
</Target>

或在实践中

<Target Name=Foo>
  <Exec Command="msbuild /v:m %(Projectlist.Identity)"/>
</Target>

,这当然可以正常工作,但是后来我再也无法获得BuildInParallel开关的功能(我不认为有可能在多个项目中不包含它们的情况下从命令行调用msbuild吗?)

and this works well off course, but then I cannot get the functionality of the BuildInParallel switch anymore (I do not think it is possible to invoke msbuild from the commandline with multiple projects without them being contained in a solution?)

更新

我接受了Ludwo的选择:基本上创建了一个自定义记录器,其中包含两个ConsoleLogger作为成员.一个是在命令行中传递的详细信息,另一个是最小".记录器将注册所有事件,并将其传递给记录器之一,具体取决于当前是否正在构建csproj文件.输出看起来与正常情况完全一样,只是它不包含来自csproj文件的数千行.

I went with Ludwo's option: basically create a custom logger that holds two ConsoleLoggers as a member. One has the verbosity passed at command line, the other one is 'minimal'. The logger registers for all events and passes them to one of the loggers depending on whether a csproj file is currently being built or not. Output looks exactly like normal, except it doesn't include thousands of lines from the csproj files.

推荐答案

您有两个选择(至少):)

You have two options (at least) :)

  1. 创建另一个用于构建abc项目的msbuild脚本 "BuildABC.proj"

  1. Create one additional msbuild script for building abc projects "BuildABC.proj"

    <Target Name="BuildABC">
      <MSBuild Projects="a.csproj;b.csproj;c.csproj" BuildInParallel="true"/>
    </Target>

在您的父脚本中,使用Exec任务执行MSBuild并调用 冗长程度最低的"BuildABC.proj"

In your parent script execute MSBuild using Exec task and call "BuildABC.proj" with minimal verbosity

    <Target Name=Foo>
      <Exec Command="msbuild /v:m /m:2 BuildABC.proj"/>
    </Target>

您必须将BuildABC项目中所需的所有父级属性明确传递给msbuild/p参数.

You have to pass explicitly all parent properties needed in the BuildABC project to msbuild /p parameter.

使用自定义记录器. 查看此操作方法.在这种情况下,您可以使用原始脚本:

Use custom logger. See this how to do it. In this case you can use your original script:

<Target Name=Foo>
  <MSBuild Projects="a.csproj;b.csproj;c.csproj"/>
</Target>

在您的自定义记录器中,请勿记录与以下内容相关的任何内容: e.ProjectFile =="a.csproj"(在使用诊断详细程度构建父项目时禁用对"a.csproj"项目的诊断日志记录)之间的ProjectStarted事件和ProjectFinished事件之间的"a.csproj"项目

In your custom logger do not log anything related to e.g. "a.csproj" project between ProjectStarted and ProjectFinished events where e.ProjectFile == "a.csproj" (to disable diagnostic logging on "a.csproj" project while building parent project with diagnostic verbosity)

这篇关于如何更改MSBuild任务的详细程度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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