@joebigelow / wix / commits / 6d431a14

Some clean up of WixToolset.BuildTasks

Rob Mensching committed Dec 19, 2021 at 10:56 UTC 6d431a1488f770a0c2c753e2e3744fbb8d3eee0b
6 files changed +30 -58
src/wix/WixToolset.BuildTasks/Common.cs
+10 -3
@@ -4,6 +4,7 @@ namespace WixToolset.BuildTasks
4 {
5 using System;
6 using System.Text.RegularExpressions;
7 + using Microsoft.Build.Framework;
8
9 /// <summary>
10 /// Common WixTasks utility methods and types.
@@ -13,8 +14,8 @@ namespace WixToolset.BuildTasks
14 /// <summary>Metadata key name to turn off harvesting of project references.</summary>
15 public const string DoNotHarvest = "DoNotHarvest";
16
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
17 + private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]");
18 + private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}"); // non 'words' and assorted valid characters
19
20 /// <summary>
21 /// Return an identifier based on passed file/directory name
@@ -24,7 +25,7 @@ namespace WixToolset.BuildTasks
25 /// <remarks>This is duplicated from WiX's Common class.</remarks>
26 public static string GetIdentifierFromName(string name)
27 {
27 - string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_".
28 + var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_".
29
30 // MSI identifiers must begin with an alphabetic character or an
31 // underscore. Prefix all other values with an underscore.
@@ -35,5 +36,11 @@ namespace WixToolset.BuildTasks
36
37 return result;
38 }
39 +
40 + public static string GetMetadataOrDefault(ITaskItem item, string metadataName, string defaultValue)
41 + {
42 + var value = item.GetMetadata(metadataName);
43 + return String.IsNullOrWhiteSpace(value) ? defaultValue : value;
44 + }
45 }
46 }
src/wix/WixToolset.BuildTasks/FileSearchHelperMethods.cs
+7 -6
@@ -33,20 +33,21 @@ namespace WixToolset.BuildTasks
33
34 if (directories == null)
35 {
36 - return string.Empty;
36 + return String.Empty;
37 }
38
39 - string fileName = Path.GetFileName(defaultFullPath);
40 - foreach (string currentPath in directories)
39 + var fileName = Path.GetFileName(defaultFullPath);
40 + foreach (var currentPath in directories)
41 {
42 - if (String.IsNullOrEmpty(currentPath) || String.IsNullOrEmpty(currentPath.Trim()))
42 + if (String.IsNullOrWhiteSpace(currentPath))
43 {
44 continue;
45 }
46
47 - if (File.Exists(Path.Combine(currentPath, fileName)))
47 + var path = Path.Combine(currentPath, fileName);
48 + if (File.Exists(path))
49 {
49 - return Path.Combine(currentPath, fileName);
50 + return path;
51 }
52 }
53
src/wix/WixToolset.BuildTasks/GetCabList.cs
+5 -15
@@ -14,27 +14,17 @@ namespace WixToolset.BuildTasks
14 /// </summary>
15 public class GetCabList : Task
16 {
17 - private ITaskItem database;
18 - private ITaskItem[] cabList;
19 -
17 /// <summary>
18 /// The list of database files to find cabs in
19 /// </summary>
20 [Required]
24 - public ITaskItem Database
25 - {
26 - get { return this.database; }
27 - set { this.database = value; }
28 - }
21 + public ITaskItem Database { get; set; }
22
23 /// <summary>
24 /// The total list of cabs in this database
25 /// </summary>
26 [Output]
34 - public ITaskItem[] CabList
35 - {
36 - get { return this.cabList; }
37 - }
27 + public ITaskItem[] CabList { get; private set; }
28
29 /// <summary>
30 /// Gets a complete list of external cabs referenced by the given installer database file.
@@ -42,8 +32,8 @@ namespace WixToolset.BuildTasks
32 /// <returns>True upon completion of the task execution.</returns>
33 public override bool Execute()
34 {
45 - string databaseFile = this.database.ItemSpec;
46 - Object []args = { };
35 + string databaseFile = this.Database.ItemSpec;
36 + object[] args = { };
37 System.Collections.Generic.List<ITaskItem> cabNames = new System.Collections.Generic.List<ITaskItem>();
38
39 // If the file doesn't exist, no cabs to return, so exit now
@@ -73,7 +63,7 @@ namespace WixToolset.BuildTasks
63 }
64 }
65
76 - this.cabList = cabNames.ToArray();
66 + this.CabList = cabNames.ToArray();
67
68 return true;
69 }
src/wix/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs
+4 -15
@@ -15,28 +15,17 @@ namespace WixToolset.BuildTasks
15 /// </summary>
16 public class RefreshBundleGeneratedFile : Task
17 {
18 - private ITaskItem[] generatedFiles;
19 - private ITaskItem[] projectReferencePaths;
20 -
18 /// <summary>
19 /// The list of files to generate.
20 /// </summary>
21 [Required]
25 - public ITaskItem[] GeneratedFiles
26 - {
27 - get { return this.generatedFiles; }
28 - set { this.generatedFiles = value; }
29 - }
22 + public ITaskItem[] GeneratedFiles { get; set; }
23
24 /// <summary>
25 /// All the project references in the project.
26 /// </summary>
27 [Required]
35 - public ITaskItem[] ProjectReferencePaths
36 - {
37 - get { return this.projectReferencePaths; }
38 - set { this.projectReferencePaths = value; }
39 - }
28 + public ITaskItem[] ProjectReferencePaths { get; set; }
29
30 /// <summary>
31 /// Gets a complete list of external cabs referenced by the given installer database file.
@@ -55,9 +44,9 @@ namespace WixToolset.BuildTasks
44 continue;
45 }
46
58 - string projectPath = CreateProjectReferenceDefineConstants.GetProjectPath(this.ProjectReferencePaths, i);
47 + string projectPath = item.GetMetadata("MSBuildSourceProjectFile");
48 string projectName = Path.GetFileNameWithoutExtension(projectPath);
60 - string referenceName = ToolsCommon.GetIdentifierFromName(CreateProjectReferenceDefineConstants.GetReferenceName(item, projectName));
49 + string referenceName = ToolsCommon.GetIdentifierFromName(ToolsCommon.GetMetadataOrDefault(item, "Name", projectName));
50
51 string[] pogs = item.GetMetadata("RefProjectOutputGroups").Split(';');
52 foreach (string pog in pogs)
src/wix/WixToolset.BuildTasks/RefreshGeneratedFile.cs
+4 -15
@@ -16,28 +16,17 @@ namespace WixToolset.BuildTasks
16 /// </summary>
17 public class RefreshGeneratedFile : Task
18 {
19 - private ITaskItem[] generatedFiles;
20 - private ITaskItem[] projectReferencePaths;
21 -
19 /// <summary>
20 /// The list of files to generate.
21 /// </summary>
22 [Required]
26 - public ITaskItem[] GeneratedFiles
27 - {
28 - get { return this.generatedFiles; }
29 - set { this.generatedFiles = value; }
30 - }
23 + public ITaskItem[] GeneratedFiles { get; set; }
24
25 /// <summary>
26 /// All the project references in the project.
27 /// </summary>
28 [Required]
36 - public ITaskItem[] ProjectReferencePaths
37 - {
38 - get { return this.projectReferencePaths; }
39 - set { this.projectReferencePaths = value; }
40 - }
29 + public ITaskItem[] ProjectReferencePaths { get; set; }
30
31 /// <summary>
32 /// Gets a complete list of external cabs referenced by the given installer database file.
@@ -55,9 +44,9 @@ namespace WixToolset.BuildTasks
44 continue;
45 }
46
58 - string projectPath = CreateProjectReferenceDefineConstants.GetProjectPath(this.ProjectReferencePaths, i);
47 + string projectPath = item.GetMetadata("MSBuildSourceProjectFile");
48 string projectName = Path.GetFileNameWithoutExtension(projectPath);
60 - string referenceName = ToolsCommon.GetIdentifierFromName(CreateProjectReferenceDefineConstants.GetReferenceName(item, projectName));
49 + string referenceName = ToolsCommon.GetIdentifierFromName(ToolsCommon.GetMetadataOrDefault(item, "Name", projectName));
50
51 string[] pogs = item.GetMetadata("RefProjectOutputGroups").Split(';');
52 foreach (string pog in pogs)
src/wix/WixToolset.Sdk/tools/wix.targets
-4
@@ -125,10 +125,6 @@
125 <UsingTask TaskName="ResolveWixReferences" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" />
126 <UsingTask TaskName="ResolveWixReferences" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath64)" Architecture="x64" />
127
128 - <UsingTask TaskName="ReplaceString" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" />
129 - <UsingTask TaskName="ReplaceString" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" />
130 - <UsingTask TaskName="ReplaceString" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath64)" Architecture="x64" />
131 -
128 <UsingTask TaskName="GenerateCompileWithObjectPath" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" />
129 <UsingTask TaskName="GenerateCompileWithObjectPath" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" />
130 <UsingTask TaskName="GenerateCompileWithObjectPath" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath64)" Architecture="x64" />