【问题标题】:documentation on how to use MSBuild Namespace in C# Source code有关如何在 C# 源代码中使用 MSBuild 命名空间的文档
【发布时间】:2011-07-25 17:59:14
【问题描述】:

我正在寻找一些关于如何在 c# 程序中使用 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();

【问题讨论】:

    标签: c#-4.0 msbuild msbuild-buildengine


    【解决方案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");
    

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

    【讨论】:

      猜你喜欢
      • 2017-10-19
      • 2010-11-02
      • 2011-12-14
      • 2014-10-25
      • 2014-05-13
      • 2016-03-28
      • 2021-11-28
      • 1970-01-01
      • 2012-01-02
      相关资源
      最近更新 更多