是否可以在项目文件中指定MSBuild自定义记录器? [英] Can a MSBuild custom Logger be specified within a Project file?

查看:109
本文介绍了是否可以在项目文件中指定MSBuild自定义记录器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

msbuild有一个命令行参数 / logger,可用于在构建时指定自定义实现的记录器。 ( https://msdn.microsoft.com/en-us/library/ms171471。 aspx

There is a command line argument '/logger' for msbuild that allows you to specify a custom implemented logger when building. (https://msdn.microsoft.com/en-us/library/ms171471.aspx)


msbuild.exe /?

msbuild.exe /?

/ logger:使用此logger记录来自MSBuild的事件。要指定
多个记录器,请分别指定每个记录器。
语法为:
[,] [;]
语法为:
[。]
语法为:
{[,] | }
是可选的,并会在您键入时将
传递给记录器。 (简短格式:/ l)
示例:
/logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral
/ logger:XMLLogger,C:\Loggers\MyLogger .dll; OutputAsHTML

/logger: Use this logger to log events from MSBuild. To specify multiple loggers, specify each logger separately. The syntax is: [,][;] The syntax is: [.] The syntax is: {[,] | } The are optional, and are passed to the logger exactly as you typed them. (Short form: /l) Examples: /logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral /logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML

我想实现自己的自定义记录器。确保我的开发团队的其余成员在每次构建时都与之一起运行;我想直接在项目文件本身中应用某种设置。

I'd like to implement my own custom logger. To make sure the rest of my development team run with it whenever they build; I want apply some sort of setting directly within the project file itself.

理想情况下,这意味着如果有人通过IDE,msbuild命令行和/或使用

Ideally this would mean if someone built the project through the IDE, msbuild command line and/or using the devenv commandline the custom logger would always be run.

在项目文件中可以使用什么设置,属性或其他机制来设置自定义记录器?

What setting, property or other mechanism could be used within the project file to set a custom logger?

推荐答案

答案是否定的。记录器是构建引擎的配置设置。您无法启动构建,然后配置构建引擎。这是来自 MSDN -它显示了构建引擎初始化的正常流程:

The answer is no. Loggers are configuration settings for build engine. You cannot start the build, and then configure the build engine. Here is a snippet of code from MSDN -- it shows normal flow of the build engine initialization:

// 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方法。但是请注意,这将是错误的,因为您将为构建中的所有项目全局修改引擎,并且该引擎可能随时无法工作或停止工作。

There might be ways to hack it, because every MSBuild task receives a reference to the build engine object (IBuildEngine interface), that you could typecast to Microsoft.BuildEngine.Engine and call RegisterLogger method. However be aware that this would be just wrong, because you will be modifying engine globally for all projects in the build, and it might not work or stop working any time.

这篇关于是否可以在项目文件中指定MSBuild自定义记录器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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