Share via


Error 任务

更新:2007 年 11 月

根据计算的条件语句停止生成操作并记录错误。

参数

下表描述了 Error 任务的参数。

参数

说明

Code

可选的 String 参数。

要与错误相关联的错误代码。

HelpKeyword

可选的 String 参数。

要与错误相关联的帮助关键字。

Text

可选的 String 参数。

Condition 参数的计算结果为 true 时,MSBuild 记录的错误文本。

备注

Error 任务使 MSBuild 项目可以向记录器发出错误文本并停止执行生成。

如果 Condition 参数的计算结果为 true,将停止生成,并记录错误。如果 Condition 参数不存在,将记录错误并停止执行生成。有关日志记录的更多信息,请参见 MSBuild 中的日志记录概述

示例

下面的代码示例验证是否所有必需的属性都已设置。如果未设置这些属性,则项目将引发错误事件,并记录 Error 任务的 Text 参数的值。

<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="ValidateCommandLine">
        <Error
            Text=" The 0 property must be set on the command line."
            Condition="'$(0)' == ''" />
        <Error
            Text="The FREEBUILD property must be set on the command line."
            Condition="'$(FREEBUILD)' == ''" />
    </Target>
    ...
</Project>

请参见

概念

MSBuild 中的日志记录概述

其他资源

MSBuild 任务参考