开发者

documentation on how to use MSBuild Namespace in C# Source code

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 li开发者_如何学Gonk 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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜