Can't get MSBuild Community Task RegexReplace to work

旧城冷巷雨未停 提交于 2019-12-06 00:39:35

Got it! It seems to have been the combination of a stupid error and a seemingly compulsory parameter. As for the first one, there were two Targets called CopyAuxiliaryFiles. As for the second one, it seems the Count parameter is needed.

The final, working version:

<Target Name="CopyCvParameters">
    <ItemGroup>
      <CvParamFiles Include="$(SolutionDir)CVParameters\DR__*" />
    </ItemGroup>
    <Message Text="Input:&#xA;@(CvParamFiles, '&#xA;')"/>
    <!-- Replaces first occurance of "foo." with empty string-->
    <RegexReplace Input="@(CvParamFiles)" Expression="^.*DR__" Replacement="$(TargetDir)Parameters\" Count="1">
      <Output ItemName ="RenamedCvParamFiles" TaskParameter="Output" />
    </RegexReplace>
    <Message Text="&#xA;Output RenamedCvParamFiles:&#xA;@(RenamedCvParamFiles, '&#xA;')" />
    <Copy SourceFiles="@(CvParamFiles)" DestinationFiles="@(RenamedCvParamFiles)" SkipUnchangedFiles="True" />
  </Target>

Notice that:

  • I renamed the Target to solve the name collision (Why doesn't Visual Studio detect this as an error?)
  • I pretty-printed the ItemGroups with the @(CvParamFiles, '&#xA;') syntax, which seems to replace ; with line breaks
  • My regex replaces the absolute path and the prefix
  • Count="1" is now passed to RegexReplace
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!