3

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

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

<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”的属性在被引用时并未使用正确的客户进行更新。我还能做些什么来确保在循环的每次迭代中“刷新”属性?

4

1 回答 1

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

那么整个目标是迭代而不是单个命令?

于 2013-08-19T13:23:18.030 回答