简体   繁体   中英

TFS and MSBuild projects Logging for each project

I'm going build large number (300+) of projects on TFS. I'm considering a proj file to manage these as follows:

<ItemGroup Label="GGX_Projects" >
<MyProj Include="$(Source)Proj1.vcxproj"  />
<MyProj Include="$(Source)Proj2.vcxproj"  />
<MyProj Include="$(Source)Proj3.csproj"  />
<MyProj Include="$(Source)Proj4.csproj"  />
<MyProj Include="$(Source)Proj5.vcxproj"  />

<MSBuild Projects="@(MyProj)" 
         Targets="ReBuid" 
         Properties="Configuration='$(Configuration)'"
         RebaseOutputs="true" 
         ContinueOnError="true"
/>

This actually working fine, but one thing I'm unable to achieve ie to get Log for each of the projects mentioned in ItemGroup.

I need separate logs, so that if any project fails, that log can be sent via e-mail.

In addition, on msbuild command line, I tried /distributedFileLogger, but unable to understand how to use this to get log file for each project separately.

Is that a correct approach? Can anyone please suggest some better solution which could provide separate logging for each project??

Distributed file logger is, as the name suggests, for logging from individual MSBuild nodes within a "distributed" build system, not for logging from individual projects, targets or tasks. You can try creating a simple custom logger, it is fairly trivial, I've written a sample below. Although, you might want to play around with event types for verbosity and use something like NLog rather than appending to files as you might get locks.

msbuild PerProjectLogger.sln /logger:PerProjectLogger\\bin\\Debug\\PerProjectLogger.dll

using System.Collections.Concurrent;
using System.IO;
using Microsoft.Build.Framework;

namespace PerProjectLogger
{
    public class Logger : Microsoft.Build.Utilities.Logger
    {
        public override void Initialize(IEventSource eventSource)
        {
            var loggers = new ConcurrentDictionary<string, FileInfo>();

            eventSource.AnyEventRaised += (s, a) =>
            {
                var property = a.GetType().GetProperty("ProjectFile");
                if (property == null)
                    return;

                var project = property.GetValue(a) as string;
                if (project == null)
                    return;

                var logger = loggers.GetOrAdd(Path.GetFileName(project), name => new FileInfo(name + ".log"));
                using (var writer = logger.AppendText())
                    writer.WriteLine(a.Message);
            };
        }
    }
}

The simplest way to achieve this with TFS is to create a single build detention and then on the Process tab you should see an option to pick solutions to build. Here you can add each Project individually. When you do a build the default build process will do a foreach project and build them. You will get a log file in the drop location for each project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM