我刚开始在我的一个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 "$(SolutionDir)\MyApplication.Wix\bin\$(Configuration)\MyApplication.msi" "$(DeploymentDirectory)\MyApplication-%(Customer.Identity)-v$(BUILD_NUMBER).MSI""></Exec>
</Target>
更新:如果我直接引用Iterator %(Customer.Identity)
而不是在“Exec”调用中使用$(DeploymentDirectory)
属性,它会起作用。像这样:
<Exec Condition="$(BuildWix) == true"
Command="copy "$(SolutionDir)\DataGateway.Wix\bin\$(Configuration)\DataGateway.msi" "$(CiRoot)DataGateway_%(Customer.Identity)_ci\DataGateway-%(Customer.Identity)-v$(BUILD_NUMBER).MSI""></Exec>
因此,在引用时,似乎没有使用正确的客户更新名为“DeploymentDirectory”的属性。我还能做些什么来确保在循环的每次迭代中“刷新”属性?
答案 0 :(得分: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
那么整个目标是迭代而不是单独的命令?