0

我正在寻找一些关于如何在 ac# 程序中使用 MSBuild 的功能的简单答案。本机文档似乎完全没用,因为我只找到如下信息:

ConsoleLogger.ApplyParameter 
Applies a parameter to the logger

这是解释的原型,最好不要写出来。无论是在此处还是在参数类型说明下,您都找不到例如链接或任何关于参数可能用于什么、它们的名称或在哪里可以找到该信息的示例

我找到的教程都是关于将 MSBuild 作为独立工具的。

目前我需要了解,如何获取有关失败构建的更多信息:此方法仅返回 true 或 false。

bool success = project.Build(new string[] { "Build", "Deploy"}, fileLogger);

我还需要了解如何配置文件记录器,以及如何从项目中使用它。

Microsoft.Build.Logging.FileLogger fileLogger = new Microsoft.Build.Logging.FileLogger();
4

1 回答 1

1

对于您问题中的特定示例,ApplyParameter 的工作方式与控制台记录器参数 (/clp) 从命令行工作的方式相同。

> msbuild /?

...

/consoleloggerparameters:<parameters>

 Parameters to console logger. (Short form: /clp)
 The available parameters are:
    PerformanceSummary--Show time spent in tasks, targets
        and projects.
    Summary--Show error and warning summary at the end.
    NoSummary--Don't show error and warning summary at the
        end.
    ErrorsOnly--Show only errors.
    WarningsOnly--Show only warnings.
    NoItemAndPropertyList--Don't show list of items and
        properties at the start of each project build.
    ShowCommandLine--Show TaskCommandLineEvent messages
    ShowTimestamp--Display the Timestamp as a prefix to any
        message.
    ShowEventId--Show eventId for started events, finished
        events, and messages
    ForceNoAlign--Does not align the text to the size of
        the console buffer
    DisableConsoleColor--Use the default console colors
        for all logging messages.
    DisableMPLogging-- Disable the multiprocessor
        logging style of output when running in
        non-multiprocessor mode.
    EnableMPLogging--Enable the multiprocessor logging
        style even when running in non-multiprocessor
        mode. This logging style is on by default.
    Verbosity--overrides the /verbosity setting for this
        logger.
 Example:
    /consoleloggerparameters:PerformanceSummary;NoSummary;
                             Verbosity=minimal

因此,对于帮助中显示的示例,

logger.ApplyParameter("PerformanceSummary", "NoSummary");
logger.ApplyParameter("Verbosity", "minimal");

如果您需要从代码对附加到构建引擎的记录器进行高度控制,您可能需要考虑编写自己的记录器,而不是尝试解释/解析来自普通控制台记录器的文本输出。

于 2011-07-25T20:15:17.653 回答