.NET Framework General Reference
Exec Task

Runs the specified program or command with 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 contains multiple lines of commands. Alternatively, you can place multiple commands in a batch file and run it using this parameter.

ExitCode

Optional Int32 output read-only parameter.

Specifies the exit code provided by the executed command.

IgnoreExitCode

Optional Boolean parameter.

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

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.

Timeout

Optional Int32 parameter.

Specifies the amount of time, in milliseconds, after which the task executable is terminated. The default value is Int.MaxValue, indicating that there is no time out period.

ToolPath

Optional String parameter.

Specifies the location from where the task will load the underlying executable file (cmd.exe).

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. One disadvantage of using the Exec task rather than a more specific task is that it cannot gather output from the tool or command that it runs.

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

Example

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>
See Also

Concepts

Other Resources

Tags :


Community Content

Sergei M. Zinovyev
Missing Properties
There are a few missing properties namely:
- CustomErrorRegularExpression
- CustomWarningRegularExpression
- IgnoreStandardErrorWarningFormat

I've posted more information on my blog at:

http://www.sedodream.com/PermaLink,guid,4571716d-c40b-4052-828f-ae2c23727e70.aspx


=================

Sayed Ibrahim Hashimi

www.sedodream.com



Daniel Fortunov
Undocumented Caveat - Calling Batch Files with Exec
If you're calling a batch script with the Exec task you may want to prefix a "CALL" at the beginning of your Command.

The reason for this is that the Exec task embeds this Command in an (undocumented) batch script of its own, and without the CALL command the outer batch will not resume execution.

This is a problem on Windows XP but on Windows 7 (and possibly XP) a change to the behaviour of CMD.EXE seems to have eliminated this problem.

For more details, see my blog post:
http://www.danielfortunov.com/software/$daniel_fortunovs_adventures_in_software_development/2009/05/21/invoking_batch_files_from_msbuild
Tags :

Conficio
Use XML Character Entities to quote
If you need to quote parameters or commands, because they contain spaces, you need to use XML Character Entities to quote, i.e. &quot;

For example:

<Exec Command="&quot;C:\Program Files\Black Duck Software\protexIP\bin\bdstool&quot; login"
WorkingDirectory="$(MSBuildProjectDirectory)"/>
Tags :

Page view tracker