MSBuild 任务参考MSBuild task reference

任务提供在生成过程中运行的代码。Tasks provide the code that runs during the build process. MSBuild 提供以下列表中的任务。The tasks in the following list are included with MSBuild. 安装 C++ 工作负载时,可使用其他任务来生成 C++ 项目。When the C++ workload is installed, additional tasks are available that are used to build C++ projects. 有关详细信息,请参阅 C++ 任务For more information, see C++ tasks.

除了此部分各主题中列出的参数外,每项任务还有下列参数:In addition to the parameters listed in the topics in this section, each task also has the following parameters:

参数Parameter 说明Description
Condition 可选 String 参数。Optional String parameter.

MSBuild 引擎使用 Boolean 表达式来确定是否执行此任务。A Boolean expression that the MSBuild engine uses to determine whether this task will be executed. 有关 MSBuild 支持的条件的信息,请参阅条件For information about the conditions that are supported by MSBuild, see Conditions.
ContinueOnError 可选参数。Optional parameter. 可以包含下列值之一:Can contain one of the following values:

- WarnAndContinuetrue- WarnAndContinue or true. 当任务失败时,Target 元素中的后续任务和生成将继续执行,并且来自该任务的所有错误都被视为警告。When a task fails, subsequent tasks in the Target element and the build continue to execute, and all errors from the task are treated as warnings.
- ErrorAndContinue- ErrorAndContinue. 当任务失败时,Target 元素中的后续任务和生成将继续执行,并且来自该任务的所有错误都被视为错误。When a task fails, subsequent tasks in the Target element and the build continue to execute, and all errors from the task are treated as errors.
- ErrorAndStopfalse (默认值)。- ErrorAndStop or false (default). 当任务失败时,将不会执行 Target 元素中的剩余任务和生成,并且整个 Target 元素和生成都被视为已失败。When a task fails, the remaining tasks in the Target element and the build aren't executed, and the entire Target element and the build is considered to have failed.

4.5 之前的 .NET Framework 版本仅支持 truefalse 值。Versions of the .NET Framework before 4.5 supported only the true and false values.

有关详细信息,请参阅如何:忽略任务中的错误For more information, see How to: Ignore errors in tasks.

在本节中In this section

向派生自 Task 类的任务添加几个参数。Adds several parameters to the tasks that derive from the Task class. 请不要直接使用。Not intended to be used directly.

向派生自 TaskExtension 类的任务添加几个参数。Adds several parameters to the tasks that derive from the TaskExtension class. 请不要直接使用。Not intended to be used directly.

向派生自 ToolTaskExtension 类的任务添加几个参数。Adds several parameters to the tasks that derive from the ToolTaskExtension class. 请不要直接使用。Not intended to be used directly.

从一个或多个文件(可以是模块,也可以是资源文件)创建一个具有清单的程序集。Creates an assembly with a manifest from one or more files that are either modules or resource files.

包装 aspnet_compiler.exe,它是预编译 ASP.NET 应用程序的实用工具。Wraps aspnet_compiler.exe , a utility to precompile ASP.NET applications.

为项分配区域性标识符。Assigns culture identifiers to items.

接受配置字符串列表,并将其分配给指定的项目。Accepts a list of configuration strings and assigns them to specified projects.

接受文件列表,并添加 <TargetPath> 属性(如果尚未指定)。Accepts a list of files and adds <TargetPath> attributes if they are not already specified.

调用项目文件中的目标。Invokes a target in the project file.

将指定路径合并到单个路径。Combines the specified paths into a single path.

将相对路径或引用转换为绝对路径。Converts a relative path or reference into an absolute path.

将文件复制到一个新位置。Copies files to a new location.

根据给定的 .resx 文件名或其他资源创建 C# 样式的清单名称。Creates a C#-style manifest name from a given .resx file name or other resource.

填充输入项中的项集合,允许从一个列表向另一个列表复制项。Populates item collections from the input items, allowing items to be copied from one list to another.

填充输入值中的属性,允许从一个属性或字符串向另一个属性或字符串复制值。Populates properties from the input values, allowing values to be copied from one property or string to another.

根据给定的 .resx 文件名或其他资源创建 Visual Basic 样式的清单名称。Creates a Visual Basic-style manifest name from a given .resx file name or other resource.

调用 Visual C# 编译器以生成可执行文件、动态链接库或代码模块。Invokes the Visual C# compiler to produce executables, dynamic-link libraries, or code modules.

删除指定的文件。Deletes the specified files.

将文件下载到指定位置。Downloads a file to the specified location.

基于评估的条件语句,停止生成操作并记录错误。Stops a build and logs an error based on an evaluated conditional statement.

使用指定参数运行指定程序或命令。Runs the specified program or command with the specified arguments.

在提供的列表中查找 app.config 文件(若有)。Finds the app.config file, if any, in the provided lists.

在指定的列表中查找具有匹配的 itemspec 的项。Finds an item in a specified list that has the matching itemspec.

确定指定项集合中的哪些项存在于指定的文件夹及其所有子文件夹中。Determines which items in the specified item collection exist in the specified folder and all of its subfolders.

将 URL 转换为正确的 URL 格式。Converts a URL to a correct URL format.

将修订号追加到版本号。Appends the revision number to the version number.

生成 ClickOnce 应用程序清单或本机清单。Generates a ClickOnce application manifest or a native manifest.

提供自动化方式来检测、下载和安装应用程序及其必备组件。Provides an automated way to detect, download, and install an application and its prerequisites.

生成 ClickOnce 部署清单。Generates a ClickOnce deployment manifest.

将 .txt 和 .resx 文件转换为公共语言运行时二进制 .resources 文件。 Converts .txt and .resx files to common language runtime binary .resources files.

从基本清单以及从 TargetZoneExcludedPermissions 属性生成应用程序信任。Generates the application trust from the base manifest, and from the TargetZone and ExcludedPermissions parameters.

从指定的文件检索程序集标识并输出标识信息。Retrieves the assembly identities from the specified files and outputs the identity information.

计算文件或文件集的内容的校验和。Computes checksums of the contents of a file or set of files.

检索 .NET Framework 程序集的路径。Retrieves the path to the .NET Framework assemblies.

检索 Windows 软件开发工具包 (SDK) 的路径。Retrieves the path to the Windows Software Development Kit (SDK).

返回各种框架的引用程序集路径。Returns the reference assembly paths of the various frameworks.

从 .licx 文件生成 .license 文件。 Generates a .license file from a .licx file.

创建目录,并在必要时创建任何父目录。Creates directories and, if necessary, any parent directories.

在生成期间记录消息。Logs a message during a build.

将文件移至新位置。Moves files to a new location.

从其他 MSBuild 项目生成 MSBuild 项目。Builds MSBuild projects from another MSBuild project.

从文本文件读取项列表。Reads a list of items from a text file.

读取指定程序集中的元数据,并在注册表中添加必要的项。Reads the metadata within the specified assembly and adds the necessary entries to the registry.

删除指定的目录及其所有文件和子目录。Removes the specified directories and all of its files and subdirectories.

从指定的项集合中删除重复的项。Removes duplicate items from the specified item collection.

确定应用程序是否需要 .NET Framework 3.5 SP1。Determines whether the application requires the .NET Framework 3.5 SP1.

  • ResGen 任务ResGen Task

已过时。Obsolete. 使用 GenerateResource 任务可以将 .txt 和 .resx 文件转换成公共语言运行时二进制 .resources 文件,反之亦然。 Use the GenerateResource task task to convert .txt and .resx files to and from common language runtime binary .resources files.

确定依赖指定程序集的所有程序集。Determines all assemblies that depend on the specified assemblies.

获取一个或多个类型库名称或 .tlb 文件的列表,将这些类型库解析为磁盘上的位置。Takes a list of one or more type library names or .tlb files and resolves those type libraries to locations on disk.

确定强名称密钥源Determines the strong name key source

在生成过程中,将以下各项解析为文件以便生成清单:生成项、依赖项、附属项、内容、调试符号和文档。Resolves the following items in the build process to files for manifest generation: built items, dependencies, satellites, content, debug symbols, and documentation.

解析本机引用。Resolves native references.

确定非 MSBuild 项目引用的输出文件。Determines the output files for non-MSBuild project references.

创建指定程序集中的类型的 XML 序列化程序集。Creates an XML serialization assembly for types in the specified assembly.

使用指定证书签署指定文件。Signs the specified file using the specified certificate.

设置文件的访问和修改时间。Sets the access and modification times of files.

注销用于 COM 互操作的指定程序集。Unregisters the specified assemblies for COM interop purposes.

将 .zip 存档解压缩到指定位置。Unzips a .zip archive to the specified location.

更新清单中所选的属性并重新签名。Updates selected properties in a manifest and resigns.

调用 Visual Basic 编译器以生成可执行文件、动态链接库或代码模块。Invokes the Visual Basic compiler to produce executables, dynamic-link libraries, or code modules..

验证文件是否与预期的文件哈希匹配。Verifies that a file matches the expected file hash.

基于评估的条件语句,在生成期间记录警告。Logs a warning during a build based on an evaluated conditional statement.

使用指定的生成代码片段,生成临时代码文件。Generates a temporary code file by using the specified generated code fragment. 不会删除该文件。Does not delete the file.

将指定项写入指定的文本文件。Writes the specified items to the specified text file.

从 XML 文件返回 XPath 查询指定的值。Returns values as specified by XPath query from an XML file.

将 XPath 查询指定的值设置为 XML 文件。Sets values as specified by an XPath query into an XML file.

使用可扩展样式表语言转换 (XSLT) 或编译的 XSLT 转换 XML 输入,并将其输出到一台输出设备或一个文件。Transforms an XML input by using an Extensible Stylesheet Language Transformation (XSLT) or compiled XSLT and outputs to an output device or a file.

根据目录内容创建 .zip 存档。Creates a .zip archive from the contents of a directory.

请参阅See also