aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/Common.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.BuildTasks/Common.cs')
-rw-r--r--src/WixToolset.BuildTasks/Common.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/WixToolset.BuildTasks/Common.cs b/src/WixToolset.BuildTasks/Common.cs
new file mode 100644
index 00000000..c5b709c2
--- /dev/null
+++ b/src/WixToolset.BuildTasks/Common.cs
@@ -0,0 +1,39 @@
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
3namespace WixToolset.BuildTasks
4{
5 using System;
6 using System.Text.RegularExpressions;
7
8 /// <summary>
9 /// Common WixTasks utility methods and types.
10 /// </summary>
11 public static class ToolsCommon
12 {
13 /// <summary>Metadata key name to turn off harvesting of project references.</summary>
14 public const string DoNotHarvest = "DoNotHarvest";
15
16 private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]", RegexOptions.Compiled);
17 private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}", RegexOptions.Compiled); // non 'words' and assorted valid characters
18
19 /// <summary>
20 /// Return an identifier based on passed file/directory name
21 /// </summary>
22 /// <param name="name">File/directory name to generate identifer from</param>
23 /// <returns>A version of the name that is a legal identifier.</returns>
24 /// <remarks>This is duplicated from WiX's Common class.</remarks>
25 public static string GetIdentifierFromName(string name)
26 {
27 string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_".
28
29 // MSI identifiers must begin with an alphabetic character or an
30 // underscore. Prefix all other values with an underscore.
31 if (AddPrefix.IsMatch(name))
32 {
33 result = String.Concat("_", result);
34 }
35
36 return result;
37 }
38 }
39}