From 88b472e81aae5bcd68255469c5f54e9e35a41ec3 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 31 Mar 2022 16:50:07 -0700 Subject: Support using response file for long command-lines in MakeSfxCA Fixes wixtoolset/issues#4688 --- .../WixToolset.Dtf.CustomAction.targets | 22 ++++-- src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs | 80 ++++++++++++++++++---- 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets b/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets index 127bb29d..9d63f24c 100644 --- a/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets +++ b/src/dtf/WixToolset.Dtf.CustomAction/WixToolset.Dtf.CustomAction.targets @@ -29,7 +29,7 @@ @(IntermediateAssembly) - Managed custom action assembly. @(Content) - Project items of type Content will be included in the package. $(CustomActionContents) - Optional space-delimited list of additional files to include. - + [OUT] $(IntermediateOutputPath)$(TargetCAFileName) - Managed custom action package with unmanaged stub. ================================================================================================== @@ -44,7 +44,7 @@ Condition=" '%(Extension)' == '.dll' or '%(Extension)' == '.exe' " /> - + @@ -60,17 +60,27 @@ - Project items of type Content - Additional items in the CustomActionContents property --> + + + + + + + + + - @(CustomActionReferenceContents);@(Content->'%(FullPath)');$(CustomActionContents) + @(IntermediateCAPackage->'%(RootDir)%(Directory)%(Filename).rsp') + + - - + - diff --git a/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs b/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs index d701da20..d9239f10 100644 --- a/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs +++ b/src/dtf/WixToolset.Dtf.MakeSfxCA/MakeSfxCA.cs @@ -3,11 +3,12 @@ namespace WixToolset.Dtf.MakeSfxCA { using System; - using System.IO; using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Reflection; using System.Security; using System.Text; - using System.Reflection; using WixToolset.Dtf.Compression; using WixToolset.Dtf.Compression.Cab; using WixToolset.Dtf.Resources; @@ -28,12 +29,12 @@ namespace WixToolset.Dtf.MakeSfxCA /// Prints usage text for the tool. /// /// Console text writer. - public static void Usage(TextWriter w) + private static void Usage(TextWriter w) { w.WriteLine("WiX Toolset custom action packager version {0}", Assembly.GetExecutingAssembly().GetName().Version); w.WriteLine("Copyright (C) .NET Foundation and contributors. All rights reserved."); w.WriteLine(); - w.WriteLine("Usage: WixToolset.Dtf.MakeSfxCA SfxCA.dll [support files ...]"); + w.WriteLine("Usage: WixToolset.Dtf.MakeSfxCA [-v] SfxCA.dll [support files ...]"); w.WriteLine(); w.WriteLine("Makes a self-extracting managed MSI CA or UI DLL package."); w.WriteLine("Support files must include " + MakeSfxCA.REQUIRED_WI_ASSEMBLY); @@ -47,20 +48,42 @@ namespace WixToolset.Dtf.MakeSfxCA /// 0 on success, nonzero on failure. public static int Main(string[] args) { - if (args.Length < 3) + var logger = TextWriter.Null; + var output = String.Empty; + var sfxDll = String.Empty; + var inputs = new List(); + + var expandedArgs = ExpandArguments(args); + + foreach (var arg in expandedArgs) + { + if (arg == "-v") + { + logger = Console.Out; + } + else if (String.IsNullOrEmpty(output)) + { + output = arg; + } + else if (String.IsNullOrEmpty(sfxDll)) + { + sfxDll = arg; + } + else + { + inputs.Add(arg); + } + } + + if (inputs.Count == 0) { Usage(Console.Out); return 1; } - var output = args[0]; - var sfxDll = args[1]; - var inputs = new string[args.Length - 2]; - Array.Copy(args, 2, inputs, 0, inputs.Length); - try { - Build(output, sfxDll, inputs, Console.Out); + Build(output, sfxDll, inputs, logger); return 0; } catch (ArgumentException ex) @@ -80,12 +103,39 @@ namespace WixToolset.Dtf.MakeSfxCA } } + /// + /// Read the arguments include parsing response files. + /// + /// Arguments to expand + /// Expanded list of arguments + private static List ExpandArguments(string[] args) + { + var result = new List(args.Length); + foreach (var arg in args) + { + if (String.IsNullOrWhiteSpace(arg)) + { + } + else if (arg.StartsWith("@")) + { + var parsed = File.ReadAllLines(arg.Substring(1)); + result.AddRange(parsed.Select(p => p.Trim('"')).Where(p => !String.IsNullOrWhiteSpace(p))); + } + else + { + result.Add(arg); + } + } + + return result; + } + /// /// Packages up all the inputs to the output location. /// /// Various exceptions are thrown /// if things go wrong. - public static void Build(string output, string sfxDll, IList inputs, TextWriter log) + private static void Build(string output, string sfxDll, IList inputs, TextWriter log) { MakeSfxCA.log = log; @@ -205,7 +255,7 @@ namespace WixToolset.Dtf.MakeSfxCA /// private static void ResolveDependentAssemblies(IDictionary inputFiles, string inputDir) { - AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += delegate(object sender, ResolveEventArgs args) + AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += delegate (object sender, ResolveEventArgs args) { AssemblyName resolveName = new AssemblyName(args.Name); Assembly assembly = null; @@ -416,7 +466,7 @@ namespace WixToolset.Dtf.MakeSfxCA foreach (var argument in attribute.ConstructorArguments) { // The entry point name is the first positional argument, if specified. - entryPointName = (string) argument.Value; + entryPointName = (string)argument.Value; break; } @@ -472,7 +522,7 @@ namespace WixToolset.Dtf.MakeSfxCA byte[] fileBytes; using (var readStream = File.OpenRead(sfxDll)) { - fileBytes = new byte[(int) readStream.Length]; + fileBytes = new byte[(int)readStream.Length]; readStream.Read(fileBytes, 0, fileBytes.Length); } -- cgit v1.2.3-55-g6feb