Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

visual studio - Nested target batching in MSBuild?

I want to execute an action per DeploymentTarget, of which there can be more than 1 per ProjectsForDeployment. I know if there was only 1 DeploymentTarget child per ProjectsForDeployment, the target batching would work - but what happens if there's multiple children? Is it still possible to run ProcessDeployableObject 4 times against A1/A2/B1/B2 whilst maintaining references to the siblings and parent?

Thanks!

<?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>
question from:https://stackoverflow.com/questions/65948350/nested-target-batching-in-msbuild

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...