// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.BuildTasks
{
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
///
/// Replaces occurances of OldValues with NewValues in String.
///
public class ReplaceString : Task
{
///
/// Text to operate on.
///
[Output]
[Required]
public string Text { get; set; }
///
/// List of old values to replace.
///
[Required]
public string OldValue { get; set; }
///
/// List of new values to replace old values with. If not specified, occurances of OldValue will be removed.
///
public string NewValue { get; set; }
///
/// Does the string replacement.
///
///
public override bool Execute()
{
if (String.IsNullOrEmpty(this.Text))
{
return true;
}
if (String.IsNullOrEmpty(this.OldValue))
{
Log.LogError("OldValue must be specified");
return false;
}
this.Text = this.Text.Replace(this.OldValue, this.NewValue);
return true;
}
}
}