简体   繁体   English

TFS和MSBuild项目每个项目的日志记录

[英]TFS and MSBuild projects Logging for each project

I'm going build large number (300+) of projects on TFS. 我将在TFS上构建大量(300多个)项目。 I'm considering a proj file to manage these as follows: 我正在考虑一个proj文件来管理这些文件,如下所示:

<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. 这实际上可以正常工作,但是我无法实现的一件事,即获取ItemGroup中提到的每个项目的Log。

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. 另外,在msbuild命令行上,我尝试了/ distributedFileLogger,但无法理解如何使用它来分别获取每个项目的日志文件。

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. 顾名思义,分布式文件记录器用于从“分布式”构建系统中的单个MSBuild节点进行日志记录,而不用于从单个项目,目标或任务进行日志记录。 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. 虽然,您可能希望处理事件类型以获取详细信息,并使用NLog东西,而不是在可能会获得锁的情况下追加到文件中。

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. 使用TFS实现此目的的最简单方法是创建一个构建滞留,然后在“进程”选项卡上,您应该看到一个选择构建解决方案的选项。 Here you can add each Project individually. 您可以在此处单独添加每个项目。 When you do a build the default build process will do a foreach project and build them. 当您进行构建时,默认的构建过程将执行一个foreach项目并对其进行构建。 You will get a log file in the drop location for each project. 您将在每个项目的放置位置获得一个日志文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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