Skip to content

Commit 0051a98

Browse files
committed
fix: outputFolder path when both output and dest are specified
1 parent 7df2c32 commit 0051a98

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

src/Docfx.App/Config/BuildJsonConfig.cs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ internal class BuildJsonConfig
4747
/// Defines the output folder of the generated build files.
4848
/// Command line --output argument prepends this value.
4949
/// </summary>
50+
[Obsolete("Use `Output` property instead. This property will be removed in a future release.")]
5051
[JsonProperty("dest")]
5152
[JsonPropertyName("dest")]
5253
public string Dest { get; set; }

src/Docfx.App/PdfBuilder.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ class Outline
4949

5050
public static Task Run(BuildJsonConfig config, string configDirectory, string? outputDirectory = null)
5151
{
52-
var outputFolder = Path.GetFullPath(Path.Combine(
53-
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, config.Output ?? "") : outputDirectory,
54-
config.Dest ?? ""));
52+
#pragma warning disable CS0618
53+
var outputFolder = Path.GetFullPath(
54+
string.IsNullOrEmpty(outputDirectory)
55+
? Path.Combine(configDirectory, config.Output ?? config.Dest ?? "")
56+
: outputDirectory);
57+
#pragma warning restore CS0618
5558

5659
Logger.LogInfo($"Searching for manifest in {outputFolder}");
5760
return CreatePdf(outputFolder);

src/Docfx.App/RunBuild.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ public static string Exec(BuildJsonConfig config, BuildOptions options, string c
2424
config.Template = new ListWithStringFallback { "default" };
2525
}
2626

27+
#pragma warning disable CS0618
2728
var baseDirectory = Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory);
28-
var outputFolder = Path.GetFullPath(Path.Combine(
29-
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(baseDirectory, config.Output ?? "") : outputDirectory,
30-
config.Dest ?? ""));
29+
var outputFolder = Path.GetFullPath(
30+
string.IsNullOrEmpty(outputDirectory)
31+
? Path.Combine(baseDirectory, config.Output ?? config.Dest ?? "")
32+
: outputDirectory);
33+
#pragma warning restore CS0618
3134

3235
EnvironmentContext.SetGitFeaturesDisabled(config.DisableGitFeatures);
3336
EnvironmentContext.SetBaseDirectory(baseDirectory);
3437

3538
try
3639
{
37-
var templateManager = new TemplateManager(config.Template, config.Theme, configDirectory);
40+
var templateManager = new TemplateManager(config.Template, config.Theme, baseDirectory);
3841

3942
DocumentBuilderWrapper.BuildDocument(config, options, templateManager, baseDirectory, outputFolder, null);
4043

src/Docfx.Dotnet/DotnetApiCatalog.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config
141141
var projects = configModel.Src;
142142
var references = configModel.References;
143143

144-
var outputFolder = Path.GetFullPath(Path.Combine(
145-
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, configModel.Output ?? "") : outputDirectory,
146-
configModel.Dest ?? ""));
144+
#pragma warning disable CS0618
145+
var outputFolder = Path.GetFullPath(
146+
string.IsNullOrEmpty(outputDirectory)
147+
? Path.Combine(configDirectory, configModel.Output ?? configModel.Dest ?? "")
148+
: outputDirectory);
149+
#pragma warning restore CS0618
147150

148151
var expandedFiles = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects);
149152
var expandedReferences = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, references);

src/Docfx.Dotnet/MetadataJsonConfig.cs

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ internal class MetadataJsonItemConfig
113113
/// Defines the output folder of the generated metadata files.
114114
/// Command line --output argument prepends this value.
115115
/// </summary>
116+
[Obsolete("Use `Output` property instead. This property will be removed in a future release.")]
116117
[JsonProperty("dest")]
117118
[JsonPropertyName("dest")]
118119
public string Dest { get; set; }

src/docfx/Models/BuildCommand.cs

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public override int Execute(CommandContext context, BuildCommandOptions settings
3131

3232
internal static void MergeOptionsToConfig(BuildCommandOptions options, BuildJsonConfig config, string configDirectory)
3333
{
34-
// base directory for content from command line is current directory
35-
// e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
36-
// for `--content "*.cs*`, base directory should be `C:\folder1`
37-
string optionsBaseDirectory = Directory.GetCurrentDirectory();
38-
3934
// Override config file with options from command line
4035
if (options.Templates != null && options.Templates.Any())
4136
{

src/docfx/Models/MergeCommand.cs

-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ private static MergeJsonConfig ParseOptions(MergeCommandOptions options, out str
3333

3434
private static void MergeOptionsToConfig(MergeCommandOptions options, ref MergeJsonItemConfig config)
3535
{
36-
// base directory for content from command line is current directory
37-
// e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
38-
// for `--content "*.cs*`, base directory should be `C:\folder1`
39-
string optionsBaseDirectory = Directory.GetCurrentDirectory();
40-
4136
if (!string.IsNullOrEmpty(options.OutputFolder)) config.Destination = Path.GetFullPath(Path.Combine(options.OutputFolder, config.Destination ?? string.Empty));
4237
}
4338
}

test/docfx.Tests/MetadataCommandTest.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task TestMetadataCommandFromCSProject()
3434
File.Copy("Assets/test.cs.sample.1", sourceFile);
3535

3636
await DotnetApiCatalog.Exec(
37-
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
37+
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
3838
new(), Directory.GetCurrentDirectory());
3939

4040
CheckResult();
@@ -48,7 +48,7 @@ public async Task TestMetadataCommandFromDll()
4848
File.Copy("Assets/test.dll.sample.1", dllFile);
4949

5050
await DotnetApiCatalog.Exec(
51-
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(dllFile)) { Expanded = true } }),
51+
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(dllFile)) { Expanded = true } }),
5252
new(), Directory.GetCurrentDirectory());
5353

5454
CheckResult();
@@ -67,7 +67,7 @@ public async Task TestMetadataCommandFromMultipleFrameworksCSProject()
6767
await DotnetApiCatalog.Exec(
6868
new(new MetadataJsonItemConfig
6969
{
70-
Dest = _outputFolder,
70+
Output = _outputFolder,
7171
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
7272
Properties = new() { ["TargetFramework"] = "net6.0" },
7373
}),
@@ -90,7 +90,7 @@ public async Task TestMetadataCommandFromVBProject()
9090
File.Copy("Assets/test.vb.sample.1", sourceFile);
9191

9292
await DotnetApiCatalog.Exec(
93-
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
93+
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
9494
new(), Directory.GetCurrentDirectory());
9595

9696
Assert.True(File.Exists(Path.Combine(_outputFolder, ".manifest")));
@@ -154,7 +154,7 @@ public async Task TestMetadataCommandFromCSProjectWithFilterInOption()
154154
await DotnetApiCatalog.Exec(
155155
new(new MetadataJsonItemConfig
156156
{
157-
Dest = _outputFolder,
157+
Output = _outputFolder,
158158
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
159159
Filter = filterFile,
160160
}),
@@ -202,7 +202,7 @@ public async Task TestMetadataCommandFromCSProjectWithDuplicateProjectReference(
202202
File.Copy("Assets/test.cs.sample.1", sourceFile);
203203

204204
await DotnetApiCatalog.Exec(
205-
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
205+
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
206206
new(), Directory.GetCurrentDirectory());
207207

208208
CheckResult();
@@ -220,7 +220,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespaces()
220220
await DotnetApiCatalog.Exec(
221221
new(new MetadataJsonItemConfig
222222
{
223-
Dest = _outputFolder,
223+
Output = _outputFolder,
224224
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
225225
NamespaceLayout = NamespaceLayout.Nested,
226226
}),
@@ -259,7 +259,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespacesWithFlat
259259
await DotnetApiCatalog.Exec(
260260
new(new MetadataJsonItemConfig
261261
{
262-
Dest = _outputFolder,
262+
Output = _outputFolder,
263263
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
264264
NamespaceLayout = NamespaceLayout.Flattened,
265265
}),
@@ -298,7 +298,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespacesWithGaps
298298
await DotnetApiCatalog.Exec(
299299
new(new MetadataJsonItemConfig
300300
{
301-
Dest = _outputFolder,
301+
Output = _outputFolder,
302302
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
303303
NamespaceLayout = NamespaceLayout.Nested,
304304
}),

0 commit comments

Comments
 (0)