From 9bbaa5d4f966f2133156d405aff76b0978dd4159 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Wed, 23 Aug 2023 18:19:57 +0900 Subject: [PATCH] feat: Enable DotnetToolMode option when creating nupkg (#9115) feat: enable DotnetToolMode option when creating nupkg. --- src/docfx/Models/TemplateCommand.cs | 12 ++++++++++-- src/docfx/docfx.csproj | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/docfx/Models/TemplateCommand.cs b/src/docfx/Models/TemplateCommand.cs index 41e77dbbafa..68656d69b33 100644 --- a/src/docfx/Models/TemplateCommand.cs +++ b/src/docfx/Models/TemplateCommand.cs @@ -14,7 +14,7 @@ public class ListCommand : Command { public override int Execute(CommandContext context) { - Directory.GetDirectories(Path.Combine(AppContext.BaseDirectory, "templates")) + Directory.GetDirectories(GetTemplateBaseDirectory()) .Select(Path.GetFileName) .ToArray() .WriteLinesToConsole(ConsoleColor.White); @@ -49,7 +49,7 @@ public override int Execute(CommandContext context, Options options) Directory.CreateDirectory(outputFolder); var templates = options.All || options.Templates is null || options.Templates.Length == 0 ? - Directory.GetDirectories(Path.Combine(AppContext.BaseDirectory, "templates")) + Directory.GetDirectories(GetTemplateBaseDirectory()) .Select(Path.GetFileName) .ToArray() : options.Templates; @@ -69,4 +69,12 @@ public override int Execute(CommandContext context, Options options) }); } } + + private static string GetTemplateBaseDirectory() + { + if (DataContracts.Common.Constants.Switches.IsDotnetToolsMode) + return Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../templates")); + + return Path.Combine(AppContext.BaseDirectory, "templates"); + } } diff --git a/src/docfx/docfx.csproj b/src/docfx/docfx.csproj index 05dada2525e..c523d68ccc6 100644 --- a/src/docfx/docfx.csproj +++ b/src/docfx/docfx.csproj @@ -7,6 +7,34 @@ The docfx command line tool published as .NET tool + + + + + $(TargetFrameworks.Split(";")[0]) + + + + + + + + + + + + + + + + + +