how to replace string in file using msbuild?

后端 未结 8 2097
庸人自扰
庸人自扰 2020-12-01 09:05

I want to replace a string such \"how r u\" in file test.xml with a string \"i am fine\" in another file xy.xml.using regular expression in ms build.

ie i have to r

8条回答
  •  误落风尘
    2020-12-01 09:36

    If you prefer not using third party (community) binaries, nor embedding code into your msbuild project, I'd suggest creating a simple task library which implements File.WriteAllText and can later host other tasks :

    using System.IO;
    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;
    
    public class FileWriteAllText : Task
    {
        [Required]
        public string Path { get; set; }
        [Required]
        public string Contents { get; set; }
    
        public override bool Execute()
        {
            File.WriteAllText(Path, Contents);
            return true;
        }
    }
    

    Then you can replace, append, etc. in msbuild :

    
    
    

提交回复
热议问题