Exec Task

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see Exec Task on docs.microsoft.com. Runs the specified program or command by using the specified arguments.

The following table describes the parameters for the Exec task.

ParameterDescription
CommandRequired 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.
CustomErrorRegularExpressionOptional 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.
CustomWarningRegularExpressionOptional 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.
ExitCodeOptional Int32 output read-only parameter.

Specifies the exit code that is provided by the executed command.
IgnoreExitCodeOptional 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.
IgnoreStandardErrorWarningFormatOptional 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.
OutputsOptional 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.
StdErrEncodingOptional String output parameter.

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

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

Specifies the directory in which the command will run.

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.

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

<Project xmlns="http://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>  

Tasks
Task Reference

Show: