14

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:

Inside my.proj:

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

On the commandline:

msbuild /v:d my.proj

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.

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>

or in practice

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

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?)

Update

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.

stijn
  • 34,664
  • 13
  • 111
  • 163
  • This post by Scott Hanselman might enlightn you. http://www.hanselman.com/blog/FasterBuildsWithMSBuildUsingParallelBuildsAndMulticoreCPUs.aspx – Carlo Kuip Oct 23 '11 at 10:47
  • + interesting read. However my projects are not contained in solutions, so the `/m` switch has not the same effect as effectively building projects in parallel: they are still built sequentially (I'll update the question to reflect this) – stijn Oct 23 '11 at 11:09
  • On one of our projects we used MSBuild Sidekick to figure out how to build our product hierachy, might be worth a look to assist on the parrallisation of tasks as well. http://www.attrice.info/msbuild/ Seems odd that verbosity is coupled to parallelism. – Carlo Kuip Oct 23 '11 at 12:30
  • it's not really coupled, it's just a side effect of me trying to get around the verbosity of the MSBuild task by invoking msbuild manually – stijn Oct 23 '11 at 16:49

1 Answers1

5

You have two options (at least) :)

  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>
    

    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>
    

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

  2. 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>
    

    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)

Ludwo
  • 6,043
  • 4
  • 32
  • 48
  • yeah I already tried this approach, as well as calling back into the same buildscript (eg in parent.proj call ``; this does work, but has one *major* disadvantage: all properties from the parent build script are not available in the other unless passed explicitely. Which becomes a major PITA when there are a lot of properties, plus each time one is added you have to add is in two places. – stijn Oct 25 '11 at 11:47
  • Thanks! I'll look into the custom logger solution when I have some time, it does look promising. – stijn Oct 25 '11 at 13:37