Can a custom MSGuild Logger be specified in a project file?

There is a '/ logger' command line argument for msbuild that allows you to specify an arbitrary built-in logger when creating. ( https://msdn.microsoft.com/en-us/library/ms171471.aspx )

msbuild.exe /?

...

/ logger: use this log to log events from MSBuild. Specify several loggers, specify each registrar separately. Syntax: [,] []; Syntax: [.] Syntax: {[,] | } They are optional and are transferred to the registrar in the same way as you dialed them. (Short form: / l) Examples: /logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral /logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML

I would like to implement my own custom logger. To make sure the rest of my development team works with it whenever they build; I want to apply some setting directly in the project file.

Ideally, this means that if someone built a project through the IDE, the msbuild command line and / or using the devenv command line, the user logger will always start.

What setting, property or other mechanism can be used in the project file to install a custom registrar?

+2
source share
2 answers

- . - . , . MSDN - :

// Instantiate a new Engine object
Engine engine = new Engine();

...

// Instantiate a new FileLogger to generate build log
FileLogger logger = new FileLogger();
// Register the logger with the engine
engine.RegisterLogger(logger);

// Build a project file
bool success = engine.BuildProjectFile(@"c:\temp\validate.proj");

//Unregister all loggers to close the log file
engine.UnregisterAllLoggers();

, MSBuild ( IBuildEngine), Microsoft.BuildEngine.Engine RegisterLogger. , , , .

+2

S.T. : . , Build, , . , , , .

. , , CustomLogger.cs. - , , , :

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace CustomLogger
{
  public class ScanLogger : Logger
  {
    public override void Initialize( IEventSource eventSource )
    {
      eventSource.MessageRaised += ( s, e ) =>
        System.Console.WriteLine( "HI THERE - " + e.Message );
    }
  }
}

Microsoft.CSharp.targets:

<PropertyGroup>
  <LoggerDll>Customlogger.dll</LoggerDll>
</PropertyGroup>

<Target Name="BuildCustomLoggerDll">
  <Csc Sources="$(MSBuildThisFileDirectory)customlogger.cs"
       References="System.dll;mscorlib.dll;Microsoft.Build.Framework.dll;Microsoft.Build.Utilities.v4.0.dll"
       TargetType="Library" OutputAssembly="$(MSBuildThisFileDirectory)$(LoggerDll)"/>
</Target>

<Target Name="ActualBuild"
        Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
        DependsOnTargets="$(BuildDependsOn)"
        Returns="$(TargetPath)"/>

<Target Name="Build">
  <Exec Command="C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe $(MSBuildThisFile) /t:ActualBuild /noconsolelogger /l:$(MSBuildThisFileDirectory)$(LoggerDll)"/>
</Target>

VS , , Build. , : DLL- BuildCustomLoggerDll, msbuild Exec , . ActualBuild, Build, C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Common.CurrentVersion.targets, , VS2013 # , , , . .

0

All Articles