0

我想为每个 DeploymentTarget 执行一个操作,其中每个 ProjectsForDeployment 可以有超过 1 个。我知道如果每个 ProjectsForDeployment 只有 1 个 DeploymentTarget 子级,那么目标批处理会起作用 - 但是如果有多个子级会发生什么?是否仍然可以对 A1/A2/B1/B2 运行 ProcessDeployableObject 4 次,同时保持对兄弟姐妹和父级的引用?

谢谢!

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name="Deploy" >
    <CallTarget Targets="ProcessDeployableProject" />
  </Target>
  
  <Target Name="ProcessDeployableProject" Inputs="@(ProjectsForDeployment)" Outputs="%(ProjectsForDeployment.Identity)\dummy.txt" >
      <!-- Processing goes here for %(ProjectsForDeployment.DeploymentTarget), needs OtherMetadataWeNeed and ProjectsForDeployment.Identity too. -->
  </Target>

  <ItemGroup>
    <ProjectsForDeployment Include="/src/A/A.csproj" >
      <DeploymentTarget>A1</DeploymentTarget>
      <DeploymentTarget>A2</DeploymentTarget>
      <OtherMetadataWeNeed>Metadata</OtherMetadataWeNeed>
    </ProjectsForDeployment>
    <ProjectsForDeployment Include="/src/B/B.csproj" >
      <DeploymentTarget>B1</DeploymentTarget>
      <DeploymentTarget>B2</DeploymentTarget>
      <OtherMetadataWeNeed>Metadata</OtherMetadataWeNeed>
    </ProjectsForDeployment>
  </ItemGroup>
</Project>
4

1 回答 1

0

To run four times, you should write four items rather than two items.

In your side, DeploymentTarget A2 will be overwritten with A1 because they are under the same item.

To solve it, you have to separate them which is more like a CSProj running with the DeploymentTarget one at a time. And when you build your project with msbuild command line, each command should work with one Configuration and Platform.

Use this:

<ItemGroup>
    <ProjectsForDeployment Include="/src/A/A.csproj" >
      <DeploymentTarget>A1</DeploymentTarget>
      <OtherMetadataWeNeed>Metadata</OtherMetadataWeNeed>
    </ProjectsForDeployment>
 
    <ProjectsForDeployment Include="/src/A/A.csproj" >
      <DeploymentTarget>A2</DeploymentTarget>
      <OtherMetadataWeNeed>Metadata</OtherMetadataWeNeed>
    </ProjectsForDeployment>


    <ProjectsForDeployment Include="/src/B/B.csproj" >
      <DeploymentTarget>B1</DeploymentTarget>    
      <OtherMetadataWeNeed>Metadata</OtherMetadataWeNeed>
    </ProjectsForDeployment>

    <ProjectsForDeployment Include="/src/B/B.csproj" >
      <DeploymentTarget>B2</DeploymentTarget>    
      <OtherMetadataWeNeed>Metadata</OtherMetadataWeNeed>
    </ProjectsForDeployment>
  </ItemGroup>
于 2021-02-01T03:14:08.443 回答