Can';无法使MSBuild社区任务RegexReplace正常工作
我正在尝试复制一组文件,这些文件的名称以前缀Can';无法使MSBuild社区任务RegexReplace正常工作,msbuild,copy,rename,msbuildcommunitytasks,Msbuild,Copy,Rename,Msbuildcommunitytasks,我正在尝试复制一组文件,这些文件的名称以前缀DR__u;开头,但副本必须删除该前缀。也就是说,DR_uuuufoo必须作为foo复制。我正在尝试这个,它基于文档(the.chm)中提供的示例: DestinationFullPath显示为空(或者这就是我在显示消息时看到的内容)。因此,Copy失败,因为没有指定destinationfile。这里怎么了 编辑:ContextVisionParameterFiles不是空的,它包含以下内容: D:\SVN.DRA.WorkingCopy\CVP
DR__u;
开头,但副本必须删除该前缀。也就是说,DR_uuuufoo
必须作为foo
复制。我正在尝试这个,它基于文档(the.chm)中提供的示例:
DestinationFullPath
显示为空(或者这就是我在显示消息时看到的内容)。因此,Copy
失败,因为没有指定destinationfile
。这里怎么了
编辑:ContextVisionParameterFiles不是空的,它包含以下内容:
D:\SVN.DRA.WorkingCopy\CVParameters\DR\uu big\u bone.alut;D:\SVN.DRA.WorkingCopy\CVParameters\DR\u big\u medium.gop
它们实际上有40个文件,但为了清晰起见,我修剪了它明白了!这似乎是一个愚蠢的错误和一个看似强制性的参数的结合。对于第一个,有两个目标称为copyaxiliaryfiles
。至于第二个,似乎需要Count
参数
最终工作版本:
<Target Name="CopyCvParameters">
<ItemGroup>
<CvParamFiles Include="$(SolutionDir)CVParameters\DR__*" />
</ItemGroup>
<Message Text="Input:
@(CvParamFiles, '
')"/>
<!-- 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="
Output RenamedCvParamFiles:
@(RenamedCvParamFiles, '
')" />
<Copy SourceFiles="@(CvParamFiles)" DestinationFiles="@(RenamedCvParamFiles)" SkipUnchangedFiles="True" />
</Target>
请注意:
- 我重命名了目标以解决名称冲突(为什么Visual Studio没有将此检测为错误?)
- 我用
@(CvParamFiles,
;')
语法漂亮地打印了ItemGroups,它似乎取代了代码>带换行符
- 我的正则表达式替换绝对路径和前缀
Count=“1”
现在传递给RegexReplace
<Target Name="CopyCvParameters">
<ItemGroup>
<CvParamFiles Include="$(SolutionDir)CVParameters\DR__*" />
</ItemGroup>
<Message Text="Input:
@(CvParamFiles, '
')"/>
<!-- 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="
Output RenamedCvParamFiles:
@(RenamedCvParamFiles, '
')" />
<Copy SourceFiles="@(CvParamFiles)" DestinationFiles="@(RenamedCvParamFiles)" SkipUnchangedFiles="True" />
</Target>