Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
MSBuild Reference
 Exec Task
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework General Reference
Exec Task

Runs the specified program or command with the specified arguments.

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.

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.

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>

Concepts

Other Resources

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Missing Properties      Sayed Ibrahim Hashimi ... Sergei M. Zinovyev   |   Edit   |   Show History
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


Undocumented Caveat - Calling Batch Files with Exec      Daniel Fortunov   |   Edit   |   Show History
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 What's this?: Add a tag
Flag as ContentBug
Use XML Character Entities to quote      Conficio   |   Edit   |   Show History
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 What's this?: Add a tag
Flag as ContentBug
Use quotes to quote      CodeMuncher   |   Edit   |   Show History

An easier way to quote parameters or commands (because they contain spaces) is using single quotes around the attribute value and regular quotes in the value.

For example:

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


Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker