diff --git a/docs/reference/docfx-json-reference.md b/docs/reference/docfx-json-reference.md index 3fdef0d2ba9..f895710be1c 100644 --- a/docs/reference/docfx-json-reference.md +++ b/docs/reference/docfx-json-reference.md @@ -295,9 +295,13 @@ Configuration options that are applied for `docfx metadata` command: Specifies the source projects using [File Mappings](#file-mappings). +### `output` + +Defines the output folder of the generated metadata files relative to `docfx.json` directory. The `docfx metadata --output ` command line argument overrides this value. + ### `dest` -Defines the output folder of the generated metadata files. Relative paths are relative to the docfx.json file being used. To go up a folder use `../`. +Defines the output folder of the generated metadata files relative to `docfx.json` directory. The `docfx metadata --output ` command line argument prepends this value. ### `shouldSkipMarkup` diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index a2119370ed1..68bf2e18a46 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -1,5 +1,10 @@ false + + $(NoWarn);NU1507 \ No newline at end of file diff --git a/samples/seed/docfx.json b/samples/seed/docfx.json index f103937b4c5..6ffb7461ca2 100644 --- a/samples/seed/docfx.json +++ b/samples/seed/docfx.json @@ -18,7 +18,7 @@ ], "namespaceLayout": "nested", "enumSortOrder": "declaringOrder", - "dest": "obj/api" + "output": "obj/api" } ], "build": { diff --git a/src/Docfx.App/Config/BuildJsonConfig.cs b/src/Docfx.App/Config/BuildJsonConfig.cs index 21c31f858d4..1f8721ba069 100644 --- a/src/Docfx.App/Config/BuildJsonConfig.cs +++ b/src/Docfx.App/Config/BuildJsonConfig.cs @@ -41,6 +41,7 @@ internal class BuildJsonConfig /// /// Defines the output folder of the generated build files. + /// Command line --output argument prepends this value. /// [Obsolete("Use output instead.")] [JsonProperty("dest")] @@ -48,6 +49,7 @@ internal class BuildJsonConfig /// /// Defines the output folder of the generated build files. + /// Command line --output argument override this value. /// [JsonProperty("output")] public string Output { get; set; } diff --git a/src/Docfx.Dotnet/DotnetApiCatalog.cs b/src/Docfx.Dotnet/DotnetApiCatalog.cs index 1db7dbff8be..6e399efb11f 100644 --- a/src/Docfx.Dotnet/DotnetApiCatalog.cs +++ b/src/Docfx.Dotnet/DotnetApiCatalog.cs @@ -68,7 +68,7 @@ internal static async Task Exec(MetadataJsonConfig config, DotnetApiOptions opti EnvironmentContext.SetGitFeaturesDisabled(item.DisableGitFeatures); // TODO: Use plugin to generate metadata for files with different extension? - using var worker = new ExtractMetadataWorker(ConvertConfig(item, outputDirectory ?? configDirectory), options); + using var worker = new ExtractMetadataWorker(ConvertConfig(item, configDirectory, outputDirectory), options); await worker.ExtractMetadataAsync(); } @@ -103,11 +103,14 @@ private static void EnsureMSBuildLocator() } } - private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig configModel, string outputDirectory) + private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig configModel, string configDirectory, string outputDirectory) { var projects = configModel.Source; var references = configModel.References; - var outputFolder = configModel.Destination ?? "_api"; + + var outputFolder = Path.GetFullPath(Path.Combine( + string.IsNullOrEmpty(outputDirectory) ? Path.Combine(configDirectory, configModel.Output ?? "") : outputDirectory, + configModel.Destination ?? "")); var expandedFiles = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects); var expandedReferences = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, references); @@ -120,7 +123,7 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config GlobalNamespaceId = configModel?.GlobalNamespaceId, MSBuildProperties = configModel?.MSBuildProperties, OutputFormat = configModel?.OutputFormat ?? default, - OutputFolder = Path.GetFullPath(Path.Combine(outputDirectory, outputFolder)), + OutputFolder = outputFolder, CodeSourceBasePath = configModel?.CodeSourceBasePath, DisableDefaultFilter = configModel?.DisableDefaultFilter ?? false, NoRestore = configModel?.NoRestore ?? false, diff --git a/src/Docfx.Dotnet/MetadataJsonConfig.cs b/src/Docfx.Dotnet/MetadataJsonConfig.cs index bc0f031c354..ca1b5c31cd5 100644 --- a/src/Docfx.Dotnet/MetadataJsonConfig.cs +++ b/src/Docfx.Dotnet/MetadataJsonConfig.cs @@ -83,10 +83,18 @@ internal class MetadataJsonItemConfig /// /// Defines the output folder of the generated metadata files. + /// Command line --output argument prepends this value. /// [JsonProperty("dest")] public string Destination { get; set; } + /// + /// Defines the output folder of the generated metadata files. + /// Command line --output argument override this value. + /// + [JsonProperty("output")] + public string Output { get; set; } + /// /// Defines the output file format. /// diff --git a/test/docfx.Snapshot.Tests/SamplesTest.cs b/test/docfx.Snapshot.Tests/SamplesTest.cs index db4873f69d9..180ff58a670 100644 --- a/test/docfx.Snapshot.Tests/SamplesTest.cs +++ b/test/docfx.Snapshot.Tests/SamplesTest.cs @@ -180,15 +180,16 @@ static string NormalizeHtml(string html) } } - [SnapshotFact] + [Fact] public async Task SeedMarkdown() { var samplePath = $"{s_samplesDir}/seed"; + var outputPath = nameof(SeedMarkdown); Clean(samplePath); - Program.Main(new[] { "metadata", $"{samplePath}/docfx.json", "--outputFormat", "markdown", "--output", nameof(SeedMarkdown) }); + Program.Main(new[] { "metadata", $"{samplePath}/docfx.json", "--outputFormat", "markdown", "--output", outputPath }); - await VerifyDirectory($"{nameof(SeedMarkdown)}/obj/api", IncludeFile, fileScrubber: ScrubFile).AutoVerify(includeBuildServer: false); + await VerifyDirectory(outputPath, IncludeFile, fileScrubber: ScrubFile).AutoVerify(includeBuildServer: false); } [SnapshotFact]