MSBuild批处理迭代器在同一迭代中不同

MSBuild批处理迭代器在同一迭代中不同,msbuild,batching,Msbuild,Batching,我刚开始在一个MSBuild脚本中使用批处理,以便为列表中的每个客户部署一次项目。一切似乎都按照计划进行,但后来我发现了一个奇怪的问题:在每次迭代结束时,任务应该制作一个MSI文件的副本,并将其放在特定于客户的目录中,使用特定于客户的文件名。发生的情况是,MSI文件被赋予了适当的名称,但两个MSI文件都被复制到同一个文件夹中(属于“Customer2”) 当我查看构建日志时,我可以看到这两个复制任务都是在构建结束时完成的。有人能解释为什么会这样吗?我想要的是在继续下一个客户之前运行整个“部署”目

我刚开始在一个MSBuild脚本中使用批处理,以便为列表中的每个客户部署一次项目。一切似乎都按照计划进行,但后来我发现了一个奇怪的问题:在每次迭代结束时,任务应该制作一个MSI文件的副本,并将其放在特定于客户的目录中,使用特定于客户的文件名。发生的情况是,MSI文件被赋予了适当的名称,但两个MSI文件都被复制到同一个文件夹中(属于“Customer2”)

当我查看构建日志时,我可以看到这两个复制任务都是在构建结束时完成的。有人能解释为什么会这样吗?我想要的是在继续下一个客户之前运行整个“部署”目标

这是MSBuild代码。我删掉了一些不相关的东西:

<PropertyGroup>
    <Customers>Customer1;Customer2</Customers>
  </PropertyGroup>

  <ItemGroup>
    <Customer Include="$(Customers)"/>
  </ItemGroup>

  <Target Name="Deploy">

    <PropertyGroup>
      <DeploymentDirectory>$(Root)MyApplication_%(Customer.Identity)_ci</DeploymentDirectory>
      <SolutionDir>../MyApplication</SolutionDir>
      <ProjectFile>$(SolutionDir)/MyApplication/MyApplication.csproj</ProjectFile>
    </PropertyGroup>

    <MSBuild Projects="web_application_deploy.msbuild" Properties="
             ProjectFile=$(ProjectFile);
             SolutionFile=$(SolutionDir)\MyApplication.sln;
             AppName=MyApplication_%(Customer.Identity)_ci;
             TestDll=$(SolutionDir)/MyApplication.Tests/bin/Release/MyApplication.Tests.dll" />


    <!-- Build WIX project-->
    <MSBuild Condition="$(BuildWix) == true"
          Projects="$(SolutionDir)\MyApplication.Wix\MyApplication.Wix.wixproj"
          Properties="DeploymentDirectory=$(DeploymentDirectory);VersionNumber=$(BUILD_NUMBER)" />

    <!-- Copying the installer file to correct path, and renaming with version number -->
    <Exec Condition="$(BuildWix) == true"
          Command="copy &quot;$(SolutionDir)\MyApplication.Wix\bin\$(Configuration)\MyApplication.msi&quot; &quot;$(DeploymentDirectory)\MyApplication-%(Customer.Identity)-v$(BUILD_NUMBER).MSI&quot;"></Exec>
  </Target>

因此,在引用名为“DeploymentDirectory”的属性时,它似乎没有使用正确的客户进行更新。是否有其他方法可以确保在循环的每次迭代中“刷新”属性?

我认为您可以这样做:

<Target Name="DeployNotBatching" >
      <Message Text="Deployment to server done here.  Deploying to server: %(Customer.Identity)" />
      <Message Text="Also called" />

</Target>
当你真的想这么做的时候

<Target Name="Deploy" Inputs="@(Customer)" Outputs="%(Identity)">
      <Message Text="Deployment to server done here.  Deploying to server: %(Customer.Identity)" />
      <Message Text="Also called" />

</Target>

因此,整个目标是迭代的,而不是单个命令?

是的,非常感谢您澄清了这一点:)我想我对批处理的工作方式有点困惑。输入/输出绝对是缺失的部分!
  Deployment to server done here.  Deploying to server: Customer1
  Deployment to server done here.  Deploying to server: Customer2
  Also called
<Target Name="Deploy" Inputs="@(Customer)" Outputs="%(Identity)">
      <Message Text="Deployment to server done here.  Deploying to server: %(Customer.Identity)" />
      <Message Text="Also called" />

</Target>
Deploy:
  Deployment to server done here.  Deploying to server: Customer1
  Also called
Deploy:
  Deployment to server done here.  Deploying to server: Customer2
  Also called