TaskLoggingHelper 类

定义

提供任务使用的帮助器记录方法。Provides helper logging methods used by tasks.

public ref class TaskLoggingHelper : MarshalByRefObject
public class TaskLoggingHelper : MarshalByRefObject
type TaskLoggingHelper = class
    inherit MarshalByRefObject
Public Class TaskLoggingHelper
Inherits MarshalByRefObject
继承
TaskLoggingHelper
派生

示例

下面的示例演示用于创建一个或多个目录的任务的代码。The following example shows the code for a task that creates one or more directories.

using System;
using System.IO;
using System.Security;
using System.Collections;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.Build.Tasks
{
    /*
     * Class: MakeDir
     *
     * An MSBuild task that creates one or more directories.
     *
     */
    public class MakeDir : Task
    {
        // The Required attribute indicates the following to MSBuild:
        //	     - if the parameter is a scalar type, and it is not supplied, fail the build immediately
        //	     - if the parameter is an array type, and it is not supplied, pass in an empty array
        // In this case the parameter is an array type, so if a project fails to pass in a value for the 
            // Directories parameter, the task will get invoked, but this implementation will do nothing,
            // because the array will be empty.
        [Required]
            // Directories to create.
        public ITaskItem[] Directories
        {
            get
            {
                return directories;
            }

            set
            {
                directories = value;
            }
        }

        // The Output attribute indicates to MSBuild that the value of this property can be gathered after the
        // task has returned from Execute(), if the project has an <Output> tag under this task's element for 
        // this property.
        [Output]
        // A project may need the subset of the inputs that were actually created, so make that available here.
        public ITaskItem[] DirectoriesCreated
        {
            get
            {
                return directoriesCreated;
            }
        }

        private ITaskItem[] directories;
        private ITaskItem[] directoriesCreated;

        /// <summary>
        /// Execute is part of the Microsoft.Build.Framework.ITask interface.
        /// When it's called, any input parameters have already been set on the task's properties.
        /// It returns true or false to indicate success or failure.
        /// </summary>
        public override bool Execute()
        {
            ArrayList items = new ArrayList();
            foreach (ITaskItem directory in Directories)
            {
                // ItemSpec holds the filename or path of an Item
                if (directory.ItemSpec.Length > 0)
                {
                    try
                    {
                        // Only log a message if we actually need to create the folder
                        if (!Directory.Exists(directory.ItemSpec))
                        {
                            Log.LogMessage(MessageImportance.Normal, "Creating directory " + directory.ItemSpec);
                            Directory.CreateDirectory(directory.ItemSpec);
                        }

                        // Add to the list of created directories
                        items.Add(directory);
                    }
                    // If a directory fails to get created, log an error, but proceed with the remaining 
                    // directories.
                    catch (Exception ex)
                    {
                        if (ex is IOException
                            || ex is UnauthorizedAccessException
                            || ex is PathTooLongException
                            || ex is DirectoryNotFoundException
                            || ex is SecurityException)
                        {
                            Log.LogError("Error trying to create directory " + directory.ItemSpec + ". " + ex.Message);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }

            // Populate the "DirectoriesCreated" output items.
            directoriesCreated = (ITaskItem[])items.ToArray(typeof(ITaskItem));

            // Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged 
            // from a task's constructor or property setter. As long as this task is written to always log an error
            // when it fails, we can reliably return HasLoggedErrors.
            return !Log.HasLoggedErrors;
        }
    }
}

构造函数

TaskLoggingHelper(IBuildEngine, String)

有助于任务工厂记录消息的公共构造函数。Public constructor which can be used by task factories to assist them in logging messages.

TaskLoggingHelper(ITask)

初始化 TaskLoggingHelper 类的新实例,并将它与指定的任务实例关联。Initializes a new instance of the TaskLoggingHelper class and associates it with the specified task instance.

属性

BuildEngine

获取与任务关联的生成引擎。Gets the build engine that is associated with the task.

HasLoggedErrors

获取一个值,该值指示此任务是否已经通过该记录帮助器对象记录了任何错误。Gets a value that indicates whether the task has logged any errors through this logging helper object.

HelpKeywordPrefix

获取或设置前缀,此前缀用于通过资源名称组成 Help 关键字。Gets or sets the prefix used to compose Help keywords from resource names.

TaskName

获取父任务的名称。Gets the name of the parent task.

TaskResources

获取或设置记录方法使用的区域性特定资源。Gets or sets the culture-specific resources used by the logging methods.

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
ExtractMessageCode(String, String)

从给定的完整消息字符串中提取消息代码前缀。Extracts the message code prefix from the given full message string.

FormatResourceString(String, Object[])

加载指定的资源字符串,并可以选择使用给定的参数设置该字符串的格式。Loads the specified resource string and optionally formats it using the given arguments.

FormatString(String, Object[])

使用给定的参数设置给定字符串的格式。Formats the given string using the given arguments.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetResourceMessage(String)

获取来自任务库中的资源的消息。Gets the message from resource in task library.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

远程控制对象被激活时,调用 InitializeLifetimeService。InitializeLifetimeService is called when the remote object is activated.

此方法将确定该对象的生存期。This method will determine how long the lifetime for the object will be.

线程安全。Thread safe. 但是,InitializeLifetimeService 和 MarkAsInactive 仅以此顺序,两者一起或不一起并且不超过一次进行调用。However, InitializeLifetimeService and MarkAsInactive should only be called in that order, together or not at all, and no more than once.

LogCommandLine(MessageImportance, String)

使用指定的重要性级别记录任务的基础工具、可执行文件或 shell 命令的命令行。Logs the command line for an underlying tool, executable file, or shell command of a task using the specified importance level.

LogCommandLine(String)

记录任务的基础工具、可执行文件或 shell 命令的命令行。Logs the command line for an underlying tool, executable file, or shell command of a task.

LogCriticalMessage(String, String, String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的字符串和其他消息详细信息记录一个重要消息。Logs a critical message using the specified string and other message details.

线程安全。Thread safe.

LogError(String, Object[])

使用指定的消息记录一个错误。Logs an error with the specified message.

LogError(String, String, String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的消息和其他错误详细信息记录一个错误。Logs an error using the specified message and other error details.

LogErrorFromException(Exception)

使用来自给定异常的消息记录一个错误。Logs an error using the message from the given exception.

LogErrorFromException(Exception, Boolean)

使用来自给定异常的消息和堆栈跟踪(可选)记录一个错误。Logs an error using the message, and optionally the stack trace, from the given exception.

LogErrorFromException(Exception, Boolean, Boolean, String)

使用来自给定异常和任何内部异常的消息和堆栈跟踪(可选)记录一个错误。Logs an error using the message, and optionally the stack-trace from the given exception and any inner exceptions.

LogErrorFromResources(String, Object[])

使用指定的资源字符串记录一个错误。Logs an error using the specified resource string.

LogErrorFromResources(String, String, String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的资源字符串和其他错误详细信息记录一个错误。Logs an error using the specified resource string and other error details.

LogErrorWithCodeFromResources(String, Object[])

使用指定的资源字符串记录一个包含错误代码的错误。Logs an error with an error code using the specified resource string.

LogErrorWithCodeFromResources(String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的资源字符串和其他错误详细信息记录一个错误。Logs an error using the specified resource string and other error details.

LogExternalProjectFinished(String, String, String, Boolean)

帮助记录自定义 ExternalProjectFinishedEventArgs 生成事件。Helps log the custom ExternalProjectFinishedEventArgs build event.

LogExternalProjectStarted(String, String, String, String)

帮助记录自定义 ExternalProjectStartedEventArgs 生成事件。Helps log the custom ExternalProjectStartedEventArgs build event.

LogMessage(MessageImportance, String, Object[])

使用指定的字符串和重要性记录一条消息。Logs a message with the specified string and importance.

LogMessage(String, Object[])

使用指定的字符串记录一条消息。Logs a message with the specified string.

LogMessage(String, String, String, String, Int32, Int32, Int32, Int32, MessageImportance, String, Object[])

使用指定的字符串和其他消息详细信息记录一个消息。Logs a message using the specified string and other message details.

线程安全。Thread safe.

LogMessageFromResources(MessageImportance, String, Object[])

使用指定的资源字符串和重要性记录一条消息。Logs a message with the specified resource string and importance.

LogMessageFromResources(String, Object[])

使用指定的资源字符串记录一条消息。Logs a message with the specified resource string.

LogMessageFromText(String, MessageImportance)

记录来自给定文本行的错误消息或警告。Logs an error message or warning from the given line of text.

LogMessagesFromFile(String)

为给定文件中的每一行文本记录错误、警告和消息。Logs errors, warnings, and messages for each line of text in the given file.

LogMessagesFromFile(String, MessageImportance)

为给定文件中的每一行文本记录错误、警告和消息。Logs errors, warnings, and messages for each line of text in the given file. 同时记录消息的重要性。Also logs the importance of messages.

LogMessagesFromStream(TextReader, MessageImportance)

记录来自给定流的错误消息或警告。Logs an error message or warning from the given stream.

LogWarning(String, Object[])

使用指定的消息记录一个警告。Logs a warning with the specified message.

LogWarning(String, String, String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的消息和其他警告详细信息记录一个警告。Logs a warning using the specified message and other warning details.

LogWarningFromException(Exception)

使用来自指定异常的消息记录一个警告。Logs a warning using the message from the specified exception.

LogWarningFromException(Exception, Boolean)

使用来自给定异常的消息和堆栈跟踪(可选)记录一个警告。Logs a warning using the message, and optionally the stack trace, from the given exception.

LogWarningFromResources(String, Object[])

使用指定的资源字符串记录一个警告。Logs a warning using the specified resource string.

LogWarningFromResources(String, String, String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的资源字符串和其他警告详细信息记录一个警告。Logs a warning using the specified resource string and other warning details.

LogWarningWithCodeFromResources(String, Object[])

使用指定的资源字符串记录一个包含警告代码的警告。Logs a warning with a warning code using the specified resource string.

LogWarningWithCodeFromResources(String, String, Int32, Int32, Int32, Int32, String, Object[])

使用指定的资源字符串和其他警告详细信息记录一个包含警告代码的警告。Logs a warning with a warning code using the specified resource string and other warning details.

MarkAsInactive()

通知此 TaskLoggingHelper 它不再被需要。Notifies this TaskLoggingHelper that it is no longer needed.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于