无法获取MSBuild社区任务RegexReplace工作 [英] Can't get MSBuild Community Task RegexReplace to work
问题描述
我试图复制一组名称以前缀 DR __
开头的文件,但是副本必须删除该前缀。也就是说, DR__foo
必须复制为 foo
。我尝试这个,这是在文档(.chm)中提供的示例:
I'm trying to copy a bunch of files whose names begin with the prefix DR__
, but the copies must have that prefix removed. That is, DR__foo
must be copied as foo
. I'm trying this, which is based in the example provided in the documentation (the .chm):
<Target Name="CopyAuxiliaryFiles">
<MakeDir Directories="$(TargetDir)Parameters" Condition="!Exists('$(TargetDir)Parameters')" />
<ItemGroup>
<ContextVisionParameterFiles Include="$(SolutionDir)CVParameters\DR__*" />
</ItemGroup>
<Message Text="Files to copy and rename: @(ContextVisionParameterFiles)"/>
<RegexReplace Input="@(ContextVisionParametersFiles)" Expression="DR__" Replacement="">
<Output ItemName ="DestinationFullPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="Renamed Files: @(DestinationFullPath)"/>
<Copy SourceFiles="@(ContextVisionParameterFiles)" DestinationFiles="@(DestinationFullPath)" />
</Target>
DestinationFullPath
我看到当我显示它与消息
)。因此,复制
失败,因为未指定 DestinationFiles
。这里有什么问题?
DestinationFullPath
comes out empty (or that's what I see when I display it with Message
). Thus, Copy
fails because no DestinationFiles
are specified. What's wrong here?
编辑:ContextVisionParameterFiles不为空,它包含:
Edit: ContextVisionParameterFiles is not empty, it contains this:
D:\SVN.DRA.WorkingCopy\CVParameters\DR__big_bone.alut; D:\SVN.DRA.WorkingCopy\CVParameters\DR__big_medium.gop
它们实际上是40个文件,但为了清晰起见,我将其修剪了
They're actually 40 files, but I trimmed it for the sake of clarity
推荐答案
收到!它似乎是一个愚蠢的错误和一个看似强制的参数的组合。至于第一个,有两个目标称为 CopyAuxiliaryFiles
。至于第二个,似乎需要 Count
参数。
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.
最终的工作版本:
<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没有检测到这是一个错误?)
- 我打印的ItemGroups与
@(CvParamFiles,'&#xA;')
语法,似乎替换;
$ b - 我的regex取代了绝对路径和前缀
-
Count =1
现在传递给RegexReplace -
- 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, '
')
syntax, which seems to replace;
with line breaks - My regex replaces the absolute path and the prefix
Count="1"
is now passed to RegexReplace
这篇关于无法获取MSBuild社区任务RegexReplace工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!