@joebigelow / wix-1 / commits / dad29a9c

Small bits of code clean-up

Rob Mensching committed Feb 3, 2022 at 04:51 UTC dad29a9c5986fe30ae6992668019e5bbca446ed0
3 files changed +27 -48
src/wix/WixToolset.BuildTasks/ResolveWixReferences.cs
+23 -31
@@ -31,11 +31,7 @@ namespace WixToolset.BuildTasks
31 /// The list of references to resolve.
32 /// </summary>
33 [Required]
34 - public ITaskItem[] WixReferences
35 - {
36 - get;
37 - set;
38 - }
34 + public ITaskItem[] WixReferences { get; set; }
35
36 /// <summary>
37 /// The directories or special locations that are searched to find the files
@@ -57,30 +53,18 @@ namespace WixToolset.BuildTasks
53 /// {RawFileName}: Specifies the task will consider the Include value of the item to be
54 /// an exact path and file name.
55 /// </summary>
60 - public string[] SearchPaths
61 - {
62 - get;
63 - set;
64 - }
56 + public string[] SearchPaths { get; set; }
57
58 /// <summary>
59 /// The filename extension(s) to be checked when searching.
60 /// </summary>
69 - public string[] SearchFilenameExtensions
70 - {
71 - get;
72 - set;
73 - }
61 + public string[] SearchFilenameExtensions { get; set; }
62
63 /// <summary>
64 /// Output items that contain the same metadata as input references and have been resolved to full paths.
65 /// </summary>
66 [Output]
79 - public ITaskItem[] ResolvedWixReferences
80 - {
81 - get;
82 - private set;
83 - }
67 + public ITaskItem[] ResolvedWixReferences { get; private set; }
68
69 /// <summary>
70 /// Resolves reference paths by searching for referenced items using the specified SearchPaths.
@@ -88,14 +72,22 @@ namespace WixToolset.BuildTasks
72 /// <returns>True on success, or throws an exception on failure.</returns>
73 public override bool Execute()
74 {
91 - List<ITaskItem> resolvedReferences = new List<ITaskItem>();
75 + var resolvedReferences = new List<ITaskItem>();
76 + var uniqueReferences = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
77
93 - foreach (ITaskItem reference in this.WixReferences)
78 + foreach (var reference in this.WixReferences)
79 {
95 - ITaskItem resolvedReference = ResolveWixReferences.ResolveReference(reference, this.SearchPaths, this.SearchFilenameExtensions, this.Log);
80 + var resolvedReference = ResolveWixReferences.ResolveReference(reference, this.SearchPaths, this.SearchFilenameExtensions, this.Log);
81
97 - this.Log.LogMessage(MessageImportance.Low, "Resolved path {0}", resolvedReference.ItemSpec);
98 - resolvedReferences.Add(resolvedReference);
82 + if (uniqueReferences.Add(resolvedReference.ItemSpec))
83 + {
84 + this.Log.LogMessage(MessageImportance.Low, "Resolved path {0}", resolvedReference.ItemSpec);
85 + resolvedReferences.Add(resolvedReference);
86 + }
87 + else
88 + {
89 + this.Log.LogMessage(MessageImportance.Low, "Resolved duplicate path {0}, discarding it", resolvedReference.ItemSpec);
90 + }
91 }
92
93 this.ResolvedWixReferences = resolvedReferences.ToArray();
@@ -130,16 +122,16 @@ namespace WixToolset.BuildTasks
122 }
123
124 // Copy all the metadata from the source
133 - TaskItem resolvedReference = new TaskItem(reference);
125 + var resolvedReference = new TaskItem(reference);
126 log.LogMessage(MessageImportance.Low, "WixReference: {0}", reference.ItemSpec);
127
128 // Now find the resolved path based on our order of precedence
137 - foreach (string searchPath in searchPaths)
129 + foreach (var searchPath in searchPaths)
130 {
131 log.LogMessage(MessageImportance.Low, "Trying {0}", searchPath);
132 if (searchPath.Equals(HintPathToken, StringComparison.Ordinal))
133 {
142 - string path = reference.GetMetadata("HintPath");
134 + var path = reference.GetMetadata("HintPath");
135 log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
136 if (File.Exists(path))
137 {
@@ -163,7 +155,7 @@ namespace WixToolset.BuildTasks
155 }
156 else
157 {
166 - string path = Path.Combine(searchPath, Path.GetFileName(reference.ItemSpec));
158 + var path = Path.Combine(searchPath, Path.GetFileName(reference.ItemSpec));
159 log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
160 if (File.Exists(path))
161 {
@@ -195,9 +187,9 @@ namespace WixToolset.BuildTasks
187 /// <returns>True if the item was resolved, else false.</returns>
188 private static bool ResolveFilenameExtensions(ITaskItem reference, string basePath, string[] filenameExtensions, TaskLoggingHelper log)
189 {
198 - foreach (string filenameExtension in filenameExtensions)
190 + foreach (var filenameExtension in filenameExtensions)
191 {
200 - string path = basePath + filenameExtension;
192 + var path = basePath + filenameExtension;
193 log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
194 if (File.Exists(path))
195 {
src/wix/WixToolset.Sdk/tools/wix.props
-2
@@ -16,8 +16,6 @@
16 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
17
18 <PropertyGroup>
19 - <Configurations Condition=" '$(Configurations)' == '' ">Debug;Release</Configurations>
20 - <Platforms Condition=" '$(Platforms)' == '' ">x86,x64,ARM64,AnyCPU</Platforms>
19 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
20 </PropertyGroup>
21
src/wix/WixToolset.Sdk/tools/wix.targets
+4 -15
@@ -70,7 +70,6 @@
70
71 <!-- Default OutputType to a known WiX Toolset type. -->
72 <OutputType Condition=" '$(OutputType)' == '' ">Package</OutputType>
73 - <AvailablePlatforms>x86,x64,ARM64,AnyCPU</AvailablePlatforms>
73
74 <WixPdbType Condition=" '$(WixPdbType)' == '' ">full</WixPdbType>
75 </PropertyGroup>
@@ -377,12 +376,7 @@
376 DependsOnTargets="$(ResolveWixLibraryReferencesDependsOn)">
377
378 <PropertyGroup>
380 - <WixLibrarySearchPaths Condition=" '$(WixLibrarySearchPaths)' == '' ">
381 - $(ReferencePaths);
382 - {HintPathFromItem};
383 - {RawFileName};
384 - $(WixExtDir)
385 - </WixLibrarySearchPaths>
379 + <WixLibrarySearchPaths Condition=" '$(WixLibrarySearchPaths)' == '' ">$(ReferencePaths);{HintPathFromItem};{RawFileName};$(WixExtDir)</WixLibrarySearchPaths>
380 </PropertyGroup>
381
382 <ResolveWixReferences
@@ -428,14 +422,9 @@
422 DependsOnTargets="$(ResolveWixExtensionReferencesDependsOn)"
423 Condition=" '@(WixExtension)' != ''">
424
431 - <CreateProperty Condition=" '$(WixExtensionSearchPaths)' == '' " Value="
432 - $(ReferencePaths);
433 - {HintPathFromItem};
434 - {RawFileName};
435 - $(WixExtDir)
436 - ">
437 - <Output TaskParameter="Value" PropertyName="WixExtensionSearchPaths" />
438 - </CreateProperty>
425 + <PropertyGroup>
426 + <WixExtensionSearchPaths Condition=" '$(WixExtensionSearchPaths)' == '' ">$(ReferencePaths);{HintPathFromItem};{RawFileName};$(WixExtDir)</WixExtensionSearchPaths>
427 + </PropertyGroup>
428
429 <ResolveWixReferences
430 WixReferences="@(WixExtension)"