gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:06:11 26 4
gpt4 key购买 nike

我刚刚开始在我的一个 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>

更新:如果我直接引用 Iterator %(Customer.Identity) 而不是在“Exec”调用中使用 $(DeploymentDirectory) 属性,它就会起作用。像这样:

<Exec Condition="$(BuildWix) == true"
Command="copy &quot;$(SolutionDir)\DataGateway.Wix\bin\$(Configuration)\DataGateway.msi&quot; &quot;$(CiRoot)DataGateway_%(Customer.Identity)_ci\DataGateway-%(Customer.Identity)-v$(BUILD_NUMBER).MSI&quot;"></Exec>

因此,似乎名为“DeploymentDirectory”的属性在被引用时未更新为正确的客户。我还能做些什么来确保属性在循环的每次迭代中都被“刷新”吗?

最佳答案

我认为你在做这样的事情:

<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

所以迭代的是整个目标而不是单个命令?

关于MSBuild 批处理迭代器在同一迭代中不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18310542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com