Skip to content

fix: OutputFolder path issue when both output and dest properties are specified #9975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Docfx.App/Config/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ internal class BuildJsonConfig
/// Defines the output folder of the generated build files.
/// Command line --output argument prepends this value.
/// </summary>
[Obsolete("Use `Output` property instead. This property will be removed in a future release.")]
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Dest { get; set; }
9 changes: 6 additions & 3 deletions src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
@@ -53,9 +53,12 @@ class Outline

public static Task Run(BuildJsonConfig config, string configDirectory, string? outputDirectory = null, CancellationToken cancellationToken = default)
{
var outputFolder = Path.GetFullPath(Path.Combine(
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, config.Output ?? "") : outputDirectory,
config.Dest ?? ""));
#pragma warning disable CS0618
var outputFolder = Path.GetFullPath(
string.IsNullOrEmpty(outputDirectory)
? Path.Combine(configDirectory, config.Output ?? config.Dest ?? "")
: outputDirectory);
#pragma warning restore CS0618

Logger.LogInfo($"Searching for manifest in {outputFolder}");
return CreatePdf(outputFolder, cancellationToken);
11 changes: 7 additions & 4 deletions src/Docfx.App/RunBuild.cs
Original file line number Diff line number Diff line change
@@ -24,17 +24,20 @@ public static string Exec(BuildJsonConfig config, BuildOptions options, string c
config.Template = ["default"];
}

#pragma warning disable CS0618
var baseDirectory = Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory);
var outputFolder = Path.GetFullPath(Path.Combine(
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(baseDirectory, config.Output ?? "") : outputDirectory,
config.Dest ?? ""));
var outputFolder = Path.GetFullPath(
string.IsNullOrEmpty(outputDirectory)
? Path.Combine(baseDirectory, config.Output ?? config.Dest ?? "")
: outputDirectory);
#pragma warning restore CS0618

EnvironmentContext.SetGitFeaturesDisabled(config.DisableGitFeatures);
EnvironmentContext.SetBaseDirectory(baseDirectory);

try
{
var templateManager = new TemplateManager(config.Template, config.Theme, configDirectory);
var templateManager = new TemplateManager(config.Template, config.Theme, baseDirectory);

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

9 changes: 6 additions & 3 deletions src/Docfx.Dotnet/DotnetApiCatalog.cs
Original file line number Diff line number Diff line change
@@ -119,9 +119,12 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config
var projects = configModel.Src;
var references = configModel.References;

var outputFolder = Path.GetFullPath(Path.Combine(
string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, configModel.Output ?? "") : outputDirectory,
configModel.Dest ?? ""));
#pragma warning disable CS0618
var outputFolder = Path.GetFullPath(
string.IsNullOrEmpty(outputDirectory)
? Path.Combine(configDirectory, configModel.Output ?? configModel.Dest ?? "")
: outputDirectory);
#pragma warning restore CS0618

var expandedFiles = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects);
var expandedReferences = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, references);
1 change: 1 addition & 0 deletions src/Docfx.Dotnet/MetadataJsonConfig.cs
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@ internal class MetadataJsonItemConfig
/// Defines the output folder of the generated metadata files.
/// Command line --output argument prepends this value.
/// </summary>
[Obsolete("Use `Output` property instead. This property will be removed in a future release.")]
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Dest { get; set; }
5 changes: 0 additions & 5 deletions src/docfx/Models/BuildCommand.cs
Original file line number Diff line number Diff line change
@@ -31,11 +31,6 @@ public override int Execute(CommandContext context, BuildCommandOptions settings

internal static void MergeOptionsToConfig(BuildCommandOptions options, BuildJsonConfig config, string configDirectory)
{
// base directory for content from command line is current directory
// e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
// for `--content "*.cs*`, base directory should be `C:\folder1`
// hence GetFullPath used below

// Override config file with options from command line
if (options.Templates != null && options.Templates.Any())
{
4 changes: 0 additions & 4 deletions src/docfx/Models/MergeCommand.cs
Original file line number Diff line number Diff line change
@@ -33,10 +33,6 @@ private static MergeJsonConfig ParseOptions(MergeCommandOptions options, out str

private static void MergeOptionsToConfig(MergeCommandOptions options, ref MergeJsonItemConfig config)
{
// base directory for content from command line is current directory
// e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
// for `--content "*.cs*`, base directory should be `C:\folder1`
// hence GetFullPath used
if (!string.IsNullOrEmpty(options.OutputFolder)) config.Destination = Path.GetFullPath(Path.Combine(options.OutputFolder, config.Destination ?? string.Empty));
}
}
18 changes: 9 additions & 9 deletions test/docfx.Tests/MetadataCommandTest.cs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public async Task TestMetadataCommandFromCSProject()
File.Copy("Assets/test.cs.sample.1", sourceFile);

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

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

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(dllFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(dllFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

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

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

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

await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig { Dest = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(new MetadataJsonItemConfig { Output = _outputFolder, Src = new(new FileMappingItem(projectFile)) { Expanded = true } }),
new(), Directory.GetCurrentDirectory());

CheckResult();
@@ -220,7 +220,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespaces()
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
NamespaceLayout = NamespaceLayout.Nested,
}),
@@ -259,7 +259,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespacesWithFlat
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
NamespaceLayout = NamespaceLayout.Flattened,
}),
@@ -298,7 +298,7 @@ public async Task TestMetadataCommandFromCSProjectWithMultipleNamespacesWithGaps
await DotnetApiCatalog.Exec(
new(new MetadataJsonItemConfig
{
Dest = _outputFolder,
Output = _outputFolder,
Src = new(new FileMappingItem(projectFile)) { Expanded = true },
NamespaceLayout = NamespaceLayout.Nested,
}),