2013-08-19 44 views
3

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

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

这是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> 

更新:它的工作原理,如果我引用了Iterator %(Customer.Identity)而不是直接使用在“执行”呼叫$(DeploymentDirectory)财产。像这样:

​​

所以看起来好像名为“DeploymentDirectory”的属性在引用时没有用正确的客户更新。还有什么我可以做的,以确保该属性在每次迭代循环中“刷新”?

回答

3

我觉得你做这样的事情:

<Target Name="DeployNotBatching" > 
     <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 

所以整个目标被重复,而不是个人的命令?

+0

是的,非常感谢清除这:)我觉得我有点困惑如何配料工作。投入/产出肯定是缺失的一块! –