From d3d3649a68cb1fa589fdd987a6690dbd5d671f0d Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 17 Sep 2017 15:35:20 -0700 Subject: Initial code commit --- src/WixToolset.BuildTasks/ReplaceString.cs | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/WixToolset.BuildTasks/ReplaceString.cs (limited to 'src/WixToolset.BuildTasks/ReplaceString.cs') diff --git a/src/WixToolset.BuildTasks/ReplaceString.cs b/src/WixToolset.BuildTasks/ReplaceString.cs new file mode 100644 index 00000000..e5041923 --- /dev/null +++ b/src/WixToolset.BuildTasks/ReplaceString.cs @@ -0,0 +1,54 @@ +// 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; + } + } +} -- cgit v1.2.3-55-g6feb