Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (29 sloc) 925 Bytes
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace MSBuild.AdditionalTasks
{
public class ReplaceTextInFileTask : Task
{
[Required] public string InputFile { get; set; }
[Required] public string OutputFile { get; set; }
[Required] public string TextToReplace { get; set; }
[Required] public string TextToReplaceWith { get; set; }
public override bool Execute()
{
try
{
var fileContent = File.ReadAllText(InputFile);
var replacedContent = fileContent.Replace(TextToReplace, TextToReplaceWith);
File.WriteAllText(OutputFile, replacedContent);
return true;
}
catch (Exception e)
{
Log.LogErrorFromException(e);
return false;
}
}
}
}
You can’t perform that action at this time.