From 6d431a1488f770a0c2c753e2e3744fbb8d3eee0b Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 19 Dec 2021 10:56:03 -0800 Subject: Some clean up of WixToolset.BuildTasks --- src/wix/WixToolset.BuildTasks/Common.cs | 13 ++++++++++--- .../WixToolset.BuildTasks/FileSearchHelperMethods.cs | 13 +++++++------ src/wix/WixToolset.BuildTasks/GetCabList.cs | 20 +++++--------------- .../RefreshBundleGeneratedFile.cs | 19 ++++--------------- .../WixToolset.BuildTasks/RefreshGeneratedFile.cs | 19 ++++--------------- src/wix/WixToolset.Sdk/tools/wix.targets | 4 ---- 6 files changed, 30 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/wix/WixToolset.BuildTasks/Common.cs b/src/wix/WixToolset.BuildTasks/Common.cs index c5b709c2..837dfb17 100644 --- a/src/wix/WixToolset.BuildTasks/Common.cs +++ b/src/wix/WixToolset.BuildTasks/Common.cs @@ -4,6 +4,7 @@ namespace WixToolset.BuildTasks { using System; using System.Text.RegularExpressions; + using Microsoft.Build.Framework; /// /// Common WixTasks utility methods and types. @@ -13,8 +14,8 @@ namespace WixToolset.BuildTasks /// Metadata key name to turn off harvesting of project references. public const string DoNotHarvest = "DoNotHarvest"; - private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]", RegexOptions.Compiled); - private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}", RegexOptions.Compiled); // non 'words' and assorted valid characters + 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 /// /// Return an identifier based on passed file/directory name @@ -24,7 +25,7 @@ namespace WixToolset.BuildTasks /// This is duplicated from WiX's Common class. public static string GetIdentifierFromName(string name) { - string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". + 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. @@ -35,5 +36,11 @@ namespace WixToolset.BuildTasks return result; } + + public static string GetMetadataOrDefault(ITaskItem item, string metadataName, string defaultValue) + { + var value = item.GetMetadata(metadataName); + return String.IsNullOrWhiteSpace(value) ? defaultValue : value; + } } } diff --git a/src/wix/WixToolset.BuildTasks/FileSearchHelperMethods.cs b/src/wix/WixToolset.BuildTasks/FileSearchHelperMethods.cs index 397c9d7c..94ff8c67 100644 --- a/src/wix/WixToolset.BuildTasks/FileSearchHelperMethods.cs +++ b/src/wix/WixToolset.BuildTasks/FileSearchHelperMethods.cs @@ -33,20 +33,21 @@ namespace WixToolset.BuildTasks if (directories == null) { - return string.Empty; + return String.Empty; } - string fileName = Path.GetFileName(defaultFullPath); - foreach (string currentPath in directories) + var fileName = Path.GetFileName(defaultFullPath); + foreach (var currentPath in directories) { - if (String.IsNullOrEmpty(currentPath) || String.IsNullOrEmpty(currentPath.Trim())) + if (String.IsNullOrWhiteSpace(currentPath)) { continue; } - if (File.Exists(Path.Combine(currentPath, fileName))) + var path = Path.Combine(currentPath, fileName); + if (File.Exists(path)) { - return Path.Combine(currentPath, fileName); + return path; } } diff --git a/src/wix/WixToolset.BuildTasks/GetCabList.cs b/src/wix/WixToolset.BuildTasks/GetCabList.cs index 33fa5b37..6e8cd991 100644 --- a/src/wix/WixToolset.BuildTasks/GetCabList.cs +++ b/src/wix/WixToolset.BuildTasks/GetCabList.cs @@ -14,27 +14,17 @@ namespace WixToolset.BuildTasks /// public class GetCabList : Task { - private ITaskItem database; - private ITaskItem[] cabList; - /// /// The list of database files to find cabs in /// [Required] - public ITaskItem Database - { - get { return this.database; } - set { this.database = value; } - } + public ITaskItem Database { get; set; } /// /// The total list of cabs in this database /// [Output] - public ITaskItem[] CabList - { - get { return this.cabList; } - } + public ITaskItem[] CabList { get; private set; } /// /// Gets a complete list of external cabs referenced by the given installer database file. @@ -42,8 +32,8 @@ namespace WixToolset.BuildTasks /// True upon completion of the task execution. public override bool Execute() { - string databaseFile = this.database.ItemSpec; - Object []args = { }; + string databaseFile = this.Database.ItemSpec; + object[] args = { }; System.Collections.Generic.List cabNames = new System.Collections.Generic.List(); // If the file doesn't exist, no cabs to return, so exit now @@ -73,7 +63,7 @@ namespace WixToolset.BuildTasks } } - this.cabList = cabNames.ToArray(); + this.CabList = cabNames.ToArray(); return true; } diff --git a/src/wix/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs b/src/wix/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs index 7663e6df..983695c9 100644 --- a/src/wix/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs +++ b/src/wix/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs @@ -15,28 +15,17 @@ namespace WixToolset.BuildTasks /// public class RefreshBundleGeneratedFile : Task { - private ITaskItem[] generatedFiles; - private ITaskItem[] projectReferencePaths; - /// /// The list of files to generate. /// [Required] - public ITaskItem[] GeneratedFiles - { - get { return this.generatedFiles; } - set { this.generatedFiles = value; } - } + public ITaskItem[] GeneratedFiles { get; set; } /// /// All the project references in the project. /// [Required] - public ITaskItem[] ProjectReferencePaths - { - get { return this.projectReferencePaths; } - set { this.projectReferencePaths = value; } - } + public ITaskItem[] ProjectReferencePaths { get; set; } /// /// Gets a complete list of external cabs referenced by the given installer database file. @@ -55,9 +44,9 @@ namespace WixToolset.BuildTasks continue; } - string projectPath = CreateProjectReferenceDefineConstants.GetProjectPath(this.ProjectReferencePaths, i); + string projectPath = item.GetMetadata("MSBuildSourceProjectFile"); string projectName = Path.GetFileNameWithoutExtension(projectPath); - string referenceName = ToolsCommon.GetIdentifierFromName(CreateProjectReferenceDefineConstants.GetReferenceName(item, projectName)); + string referenceName = ToolsCommon.GetIdentifierFromName(ToolsCommon.GetMetadataOrDefault(item, "Name", projectName)); string[] pogs = item.GetMetadata("RefProjectOutputGroups").Split(';'); foreach (string pog in pogs) diff --git a/src/wix/WixToolset.BuildTasks/RefreshGeneratedFile.cs b/src/wix/WixToolset.BuildTasks/RefreshGeneratedFile.cs index c57e3f0f..e18ae222 100644 --- a/src/wix/WixToolset.BuildTasks/RefreshGeneratedFile.cs +++ b/src/wix/WixToolset.BuildTasks/RefreshGeneratedFile.cs @@ -16,28 +16,17 @@ namespace WixToolset.BuildTasks /// public class RefreshGeneratedFile : Task { - private ITaskItem[] generatedFiles; - private ITaskItem[] projectReferencePaths; - /// /// The list of files to generate. /// [Required] - public ITaskItem[] GeneratedFiles - { - get { return this.generatedFiles; } - set { this.generatedFiles = value; } - } + public ITaskItem[] GeneratedFiles { get; set; } /// /// All the project references in the project. /// [Required] - public ITaskItem[] ProjectReferencePaths - { - get { return this.projectReferencePaths; } - set { this.projectReferencePaths = value; } - } + public ITaskItem[] ProjectReferencePaths { get; set; } /// /// Gets a complete list of external cabs referenced by the given installer database file. @@ -55,9 +44,9 @@ namespace WixToolset.BuildTasks continue; } - string projectPath = CreateProjectReferenceDefineConstants.GetProjectPath(this.ProjectReferencePaths, i); + string projectPath = item.GetMetadata("MSBuildSourceProjectFile"); string projectName = Path.GetFileNameWithoutExtension(projectPath); - string referenceName = ToolsCommon.GetIdentifierFromName(CreateProjectReferenceDefineConstants.GetReferenceName(item, projectName)); + string referenceName = ToolsCommon.GetIdentifierFromName(ToolsCommon.GetMetadataOrDefault(item, "Name", projectName)); string[] pogs = item.GetMetadata("RefProjectOutputGroups").Split(';'); foreach (string pog in pogs) diff --git a/src/wix/WixToolset.Sdk/tools/wix.targets b/src/wix/WixToolset.Sdk/tools/wix.targets index fde969e6..6b15769a 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.targets +++ b/src/wix/WixToolset.Sdk/tools/wix.targets @@ -125,10 +125,6 @@ - - - - -- cgit v1.2.3-55-g6feb