且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在“循环"窗口中执行EXEC任务?与MSBuild ItemGroups?

更新时间:1970-01-01 07:58:30

有两种方法,两种都是批处理"的形式

There are two ways to do this, both are forms of "batching"

您可以批处理目标并执行Exec和其他操作,

You can batch a target and perform the Exec and other operations,

<Target Name="ExecMany"
  Outputs="%(CachedTables.Identity)">
  <Exec
    Command="sqlcmd -S ... TableName=%22%(CachedTables.Identity)%22 -i ..."
    />
  <SomeOtherTask ThatUses="%(CachedTables.Identity)" />
</Target>

另一种方法是仅在Exec任务上使用任务批处理.相似

The other is to use task batching, just on the Exec task. It is similar,

<Target Name="ExecMany">
  <Exec
    Command="sqlcmd -S ... TableName=%22%(CachedTables.Identity)%22 -i ..."
    />
  <SomeOtherTask ThatUses="%(CachedTables.Identity)" />
</Target>

区别在于它们将如何运行.首先,由于批处理针对整个目标(通过Outputs属性实现),即Exec任务,因此SomeOtherTask将针对组中的每个项目执行.换句话说,

The difference is how these will operate. With the first, since the batching is for the whole target (achieved with the Outputs attribute), the Exec task, then the SomeOtherTask will execute for each item in the group. In other words,

Exec with "account"
SomeOtherTask with "account"
Exec with "services"
SomeOtherTask with "services"
...

第二个选项,分别分批处理每个任务,将产生以下顺序,

The second options, batching each task separately, would produce the following sequence,

Exec with "account"
Exec with "services"
...
SomeOtherTask with "account"
SomeOtherTask with "services"
...