MSBuild在构建期间编辑XML .proj文件,删除节点

时间:2015-09-03 20:33:11

标签: xml msbuild

我有一个msbuild项目文件:

<Project ToolsVersion="4.0" DefaultTargets="Build" ...">
<ItemGroup>
   <ProjectReference Include="1.csproj">
      <Project>{a1}</Project>
      <Name>Some info1</Name>
    </ProjectReference>
    <ProjectReference Include="2.csproj">
      <Project>{a2}</Project>
      <Name>some info2</Name>
    </ProjectReference>
</ItemGroup

我需要从&#39; ItemGroup中删除第二个节点ProjectReference,如下所示:

<Project ToolsVersion="4.0" DefaultTargets="Build" ...">
<ItemGroup>
   <ProjectReference Include="1.csproj">
      <Project>{a1}</Project>
      <Name>Some info1</Name>
    </ProjectReference>
</ItemGroup

怎么做?我试过这个:

<TransformXml Source="$(ProjectPath)"
  Transform="%(ProjectReference.Identity)"
  Destination="$(ProjectPath)"
  Condition=" '@(ProjectReference.Identity)'='1.csproj'" />

但它没有用。我也尝试过这个:

<XmlUpdate
      XmlFileName="$(ProjectPath)"
      XPath="//Project/ItemGroup/ProjectReference[@Include='%(ProjectReference.Identity)']"
      Delete="true"
      Condition=" '@(ProjectReference.Identity)'='1.csproj'"/>

0 个答案:

没有答案