【问题标题】:MSBuild How do do String replacement in an item listMSBuild如何在项目列表中进行字符串替换
【发布时间】:2012-08-15 19:32:22
【问题描述】:

虽然我在学习 MSBuild 脚本方面取得了不错的进步,但我仍然认为自己是初学者,所以请放轻松。

我有一个 MSBuild 脚本,它运行一个工作项查询并将其输出到一个文件,我转身阅读该文件

<ReadLinesFromFile File="output.txt">
<Output ItemName="ItemList"  TaskParameter="Lines"/>
</ReadLinesFromFile>

文件中的行包含一个 ID 号、一个用户名和一个任务描述。为了“漂亮起来”,我想用人名替换文件中的用户名,即将 jdoe 更改为 John Doe,所以我认为扩展包中的 TextString 任务是正确的做法,但我不这样做'不要对列表进行任何更改。一旦我得到这个工作,我会想为我的所有团队成员复制它。

<TextString TaskAction="Replace" OldString="@(ItemList)" OldValue="jdoe" NewValue="John Doe">
  <Output PropertyName="ItemList" TaskParameter="NewString"/>
</TextString>
<Message Text="Results: @(ItemList)" />

脚本不会崩溃或出错,但也不会进行替换。怎么了?

【问题讨论】:

    标签: msbuild replace readlines


    【解决方案1】:

    您可以尝试文件系统任务操作。我认为问题在于您使用的是项目列表而不是 $property 元素

    <MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" 
    TextEncoding="ASCII"  RegexPattern='"Jdoe"' 
    Replacement='"John Doe"' 
    Files="%(output.txt)"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-29
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      相关资源
      最近更新 更多