diff options
Diffstat (limited to 'src/tools/WixToolset.HeatTasks/RefreshTask.cs')
-rw-r--r-- | src/tools/WixToolset.HeatTasks/RefreshTask.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/WixToolset.HeatTasks/RefreshTask.cs b/src/tools/WixToolset.HeatTasks/RefreshTask.cs new file mode 100644 index 00000000..0b378272 --- /dev/null +++ b/src/tools/WixToolset.HeatTasks/RefreshTask.cs | |||
@@ -0,0 +1,59 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.HeatTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Text.RegularExpressions; | ||
7 | using Microsoft.Build.Framework; | ||
8 | using Microsoft.Build.Utilities; | ||
9 | |||
10 | /// <summary> | ||
11 | /// A base MSBuild task to refresh generated files. | ||
12 | /// </summary> | ||
13 | public abstract class RefreshTask : Task | ||
14 | { | ||
15 | private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]"); | ||
16 | private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}"); // non 'words' and assorted valid characters | ||
17 | |||
18 | /// <summary>Metadata key name to turn off harvesting of project references.</summary> | ||
19 | protected const string DoNotHarvest = "DoNotHarvest"; | ||
20 | |||
21 | /// <summary> | ||
22 | /// The list of files to generate. | ||
23 | /// </summary> | ||
24 | [Required] | ||
25 | public ITaskItem[] GeneratedFiles { get; set; } | ||
26 | |||
27 | /// <summary> | ||
28 | /// All the project references in the project. | ||
29 | /// </summary> | ||
30 | [Required] | ||
31 | public ITaskItem[] ProjectReferencePaths { get; set; } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Return an identifier based on passed file/directory name | ||
35 | /// </summary> | ||
36 | /// <param name="name">File/directory name to generate identifer from</param> | ||
37 | /// <returns>A version of the name that is a legal identifier.</returns> | ||
38 | /// <remarks>This is duplicated from WiX's Common class.</remarks> | ||
39 | protected static string GetIdentifierFromName(string name) | ||
40 | { | ||
41 | var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". | ||
42 | |||
43 | // MSI identifiers must begin with an alphabetic character or an | ||
44 | // underscore. Prefix all other values with an underscore. | ||
45 | if (AddPrefix.IsMatch(name)) | ||
46 | { | ||
47 | result = String.Concat("_", result); | ||
48 | } | ||
49 | |||
50 | return result; | ||
51 | } | ||
52 | |||
53 | protected static string GetMetadataOrDefault(ITaskItem item, string metadataName, string defaultValue) | ||
54 | { | ||
55 | var value = item.GetMetadata(metadataName); | ||
56 | return String.IsNullOrWhiteSpace(value) ? defaultValue : value; | ||
57 | } | ||
58 | } | ||
59 | } | ||