有关如何在 C# 源代码中使用 MSBuild 命名空间的文档

发布于 2024-11-26 09:35:18 字数 595 浏览 3 评论 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();

I am looking for some simple answers on how to use funktionality from MSBuild in a c# program. The native documentation seems to be completely useless, because I only find information like:

ConsoleLogger.ApplyParameter 
Applies a parameter to the logger

This is the prototype of a explanation, that had better never been written. Neither here, nor under the parameters type explanation you find e.g. a link or any examples about what the parameters might be there for, or their names, or where to find that information

The tutorials I find are all about MSBuild as a standalone tool.

At the moment I need to understand, how to get more information about a failed build:
This method just returns true or false.

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

Also I need understand how to configure the filelogger, and how to use it from project.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如此安好 2024-12-03 09:35:18

对于您问题中的特定示例,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");

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

For the particular example in your question, ApplyParameter works the same way that the console logger parameters (/clp) work from the command line.

> 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

So for the example shown in the help,

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

If you need a high degree of control over a logger you are attaching to the build engine from code, you might want to consider writing your own logger rather than trying to interpret/parse the text output from the stock console logger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文