Default output file if there's a single input file.
Bob Arnson committed
May 8, 2020 at 20:25 UTC
d47527d4af6066969ea9abee83ef9b172e4e1d98
1 file changed
+71
-4
src/WixToolset.Core/CommandLine/BuildCommand.cs
+71
-4
@@ -74,8 +74,6 @@ namespace WixToolset.Core.CommandLine
74
75
this.Platform = this.commandLine.Platform;
76
77
- this.OutputFile = this.commandLine.OutputFile;
78
-
77
this.ContentsFile = this.commandLine.ContentsFile;
78
79
this.OutputsFile = this.commandLine.OutputsFile;
@@ -92,6 +90,21 @@ namespace WixToolset.Core.CommandLine
90
91
this.EvaluateSourceFiles(sourceFiles, creator, out var codeFiles, out var wixipl);
92
93
+ this.OutputFile = this.commandLine.OutputFile;
94
+
95
+ if (String.IsNullOrEmpty(this.OutputFile))
96
+ {
97
+ if (codeFiles.Count == 1)
98
+ {
99
+ // If output type is unknown, the extension will be replaced with the right default based on output type.
100
+ this.OutputFile = Path.ChangeExtension(codeFiles[0].OutputPath, DefaultExtensionForOutputType(this.OutputType));
101
+ }
102
+ else
103
+ {
104
+ this.Messaging.Write(ErrorMessages.MustSpecifyOutputWithMoreThanOneInput());
105
+ }
106
+ }
107
+
108
if (this.Messaging.EncounteredError)
109
{
110
return this.Messaging.LastErrorNumber;
@@ -114,7 +127,7 @@ namespace WixToolset.Core.CommandLine
127
128
if (!this.Messaging.EncounteredError)
129
{
117
- wixlib.Save(this.commandLine.OutputFile);
130
+ wixlib.Save(this.OutputFile);
131
}
132
}
133
}
@@ -129,9 +142,16 @@ namespace WixToolset.Core.CommandLine
142
143
if (!this.Messaging.EncounteredError)
144
{
145
+ var outputExtension = Path.GetExtension(this.OutputFile);
146
+ if (String.IsNullOrEmpty(outputExtension) || ".wix" == outputExtension)
147
+ {
148
+ var entrySectionType = wixipl.Sections.Single().Type;
149
+ this.OutputFile = Path.ChangeExtension(this.OutputFile, DefaultExtensionForSectionType(entrySectionType));
150
+ }
151
+
152
if (this.OutputType == OutputType.IntermediatePostLink)
153
{
134
- wixipl.Save(this.commandLine.OutputFile);
154
+ wixipl.Save(this.OutputFile);
155
}
156
else
157
{
@@ -416,6 +436,53 @@ namespace WixToolset.Core.CommandLine
436
return result?.Document;
437
}
438
439
+ private static string DefaultExtensionForSectionType(SectionType sectionType)
440
+ {
441
+ switch (sectionType)
442
+ {
443
+ case SectionType.Bundle:
444
+ return ".exe";
445
+ case SectionType.Module:
446
+ return ".msm";
447
+ case SectionType.Product:
448
+ return ".msi";
449
+ case SectionType.PatchCreation:
450
+ return ".pcp";
451
+ case SectionType.Patch:
452
+ return ".msp";
453
+ case SectionType.Fragment:
454
+ case SectionType.Unknown:
455
+ default:
456
+ return ".wix";
457
+ }
458
+ }
459
+
460
+ private static string DefaultExtensionForOutputType(OutputType outputType)
461
+ {
462
+ switch (outputType)
463
+ {
464
+ case OutputType.Bundle:
465
+ return ".exe";
466
+ case OutputType.Library:
467
+ return ".wixlib";
468
+ case OutputType.Module:
469
+ return ".msm";
470
+ case OutputType.Patch:
471
+ return ".msp";
472
+ case OutputType.PatchCreation:
473
+ return ".pcp";
474
+ case OutputType.Product:
475
+ return ".msi";
476
+ case OutputType.Transform:
477
+ return ".mst";
478
+ case OutputType.IntermediatePostLink:
479
+ return ".wixipl";
480
+ case OutputType.Unknown:
481
+ default:
482
+ return ".wix";
483
+ }
484
+ }
485
+
486
private class CommandLine
487
{
488
private static readonly char[] BindPathSplit = { '=' };