Exec Task

Runs the specified program or command by using the specified arguments.

Parameters

The following table describes the parameters for the Exec task.

Parameter

Description

Command

Required String parameter.

The command(s) to run. These can be system commands, such as attrib, or an executable, such as program.exe, runprogram.bat, or setup.msi.

This parameter can contain multiple lines of commands. Alternatively, you can put multiple commands in a batch file and run it by using this parameter.

CustomErrorRegularExpression

Optional String parameter.

Specifies a regular expression that is used to spot error lines in the tool output. This is useful for tools that produce unusually formatted output.

CustomWarningRegularExpression

Optional String parameter.

Specifies a regular expression that is used to spot warning lines in the tool output. This is useful for tools that produce unusually formatted output.

ExitCode

Optional Int32 output read-only parameter.

Specifies the exit code that is provided by the executed command.

IgnoreExitCode

Optional Boolean parameter.

If true, the task ignores the exit code that is provided by the executed command. Otherwise, the task returns false if the executed command returns a non-zero exit code.

IgnoreStandardErrorWarningFormat

Optional Boolean parameter.

If false, selects lines in the output that match the standard error/warning format, and logs them as errors/warnings. If true, disable this behavior.

Outputs

Optional ITaskItem[] output parameter.

Contains the output items from the task. The Exec task does not set these itself. Instead, you can provide them as if it did set them, so that they can be used later in the project.

StdErrEncoding

Optional String output parameter.

Specifies the encoding of the captured task standard error stream. The default is the current console output encoding.

StdOutEncoding

Optional String output parameter.

Specifies the encoding of the captured task standard output stream. The default is the current console output encoding.

WorkingDirectory

Optional String parameter.

Specifies the directory in which the command will run.

Remarks

This task is useful when a specific MSBuild task for the job that you want to perform is not available. However, the Exec task, unlike a more specific task, cannot gather output from the tool or command that it runs.

The Exec task calls cmd.exe instead of directly invoking a process.

In addition to the parameters listed in this document, this task inherits parameters from the ToolTaskExtension class, which itself inherits from the ToolTask class. For a list of these additional parameters and their descriptions, see ToolTaskExtension Base Class.

Example

The following example uses the Exec task to run a command.

<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Binaries Include="*.dll;*.exe"/>
    </ItemGroup>

    <Target Name="SetACL">
        <!-- set security on binaries-->
        <Exec Command="echo y| cacls %(Binaries.Identity) /G everyone:R"/>
    </Target>

</Project>

See Also

Concepts

MSBuild Tasks

Other Resources

MSBuild Task Reference