// 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.HeatTasks { using System; using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; /// /// A base MSBuild task to refresh generated files. /// public abstract class RefreshTask : Task { private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]"); private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}"); // non 'words' and assorted valid characters /// Metadata key name to turn off harvesting of project references. protected const string DoNotHarvest = "DoNotHarvest"; /// /// The list of files to generate. /// [Required] public ITaskItem[] GeneratedFiles { get; set; } /// /// All the project references in the project. /// [Required] public ITaskItem[] ProjectReferencePaths { get; set; } /// /// Return an identifier based on passed file/directory name /// /// File/directory name to generate identifer from /// A version of the name that is a legal identifier. /// This is duplicated from WiX's Common class. protected static string GetIdentifierFromName(string name) { var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". // MSI identifiers must begin with an alphabetic character or an // underscore. Prefix all other values with an underscore. if (AddPrefix.IsMatch(name)) { result = String.Concat("_", result); } return result; } protected static string GetMetadataOrDefault(ITaskItem item, string metadataName, string defaultValue) { var value = item.GetMetadata(metadataName); return String.IsNullOrWhiteSpace(value) ? defaultValue : value; } } }