From 538a2274d713cc448f218d812ee239f213152141 Mon Sep 17 00:00:00 2001 From: Thomas Ibel Date: Fri, 2 Dec 2022 17:38:32 +0100 Subject: [PATCH 1/2] remove NetCore conditions --- .../Loggers/AggregatedLogListener.cs | 17 ++++------------- .../Loggers/ConsoleLogListener.cs | 4 +--- .../Loggers/CrossAppDomainListener.cs | 4 +--- .../Loggers/HtmlLogListener.cs | 2 -- .../Loggers/Logger.cs | 18 ------------------ .../Loggers/LoggerFileScope.cs | 4 +--- .../Loggers/PerformanceScope.cs | 4 +--- .../Loggers/ReplayLogListener.cs | 17 ++++------------- .../FullObjectGraphTraversalStrategy.cs | 2 -- 9 files changed, 12 insertions(+), 60 deletions(-) diff --git a/src/Microsoft.DocAsCode.Common/Loggers/AggregatedLogListener.cs b/src/Microsoft.DocAsCode.Common/Loggers/AggregatedLogListener.cs index 40db49cac2f..e1345c210b7 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/AggregatedLogListener.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/AggregatedLogListener.cs @@ -6,11 +6,7 @@ namespace Microsoft.DocAsCode.Common using System; using System.Collections.Generic; using System.Linq; -#if NetCore - using AggregatedList = System.Collections.Generic.SortedDictionary>; -#else - using AggregatedList = System.Collections.Generic.SortedList>; -#endif + /// /// Replay aggregated log on flushing /// @@ -18,7 +14,7 @@ public class AggregatedLogListener : ILoggerListener { private readonly LogLevel _threshold; private readonly ILoggerListener _innerListener; - private readonly AggregatedList _aggregatedList; + private readonly SortedList> _aggregatedList; public AggregatedLogListener(AggregatedLogListener other) : this(other._threshold) { @@ -28,7 +24,7 @@ public AggregatedLogListener(AggregatedLogListener other) : this(other._threshol public AggregatedLogListener(LogLevel threshold = LogLevel.Warning) { _threshold = threshold; - _aggregatedList = new AggregatedList(); + _aggregatedList = new SortedList>(); _innerListener = new ConsoleLogListener(); for (LogLevel level = _threshold; level <= LogLevel.Error; level++) { @@ -87,17 +83,14 @@ private void WriteHeader(BuildStatus status) default: break; } -#if !NetCore + WriteToConsole(message, status); -#endif } private void WriteFooter(BuildStatus status) { var footer = string.Join(Environment.NewLine, _aggregatedList.Select(s => $"\t{s.Value.Count} {s.Key}(s)")); -#if !NetCore WriteToConsole(footer, status); -#endif } private void WriteLineCore(ILogItem item) @@ -105,7 +98,6 @@ private void WriteLineCore(ILogItem item) _innerListener.WriteLine(item); } -#if !NetCore private static void WriteToConsole(string message, BuildStatus status) { switch (status) @@ -128,7 +120,6 @@ private static void WriteToConsole(string message, ConsoleColor color = ConsoleC { ConsoleUtility.WriteLine(message, color); } -#endif private static BuildStatus GetBuildStatusFromLogLevel(LogLevel level) { diff --git a/src/Microsoft.DocAsCode.Common/Loggers/ConsoleLogListener.cs b/src/Microsoft.DocAsCode.Common/Loggers/ConsoleLogListener.cs index 0b72ea1200a..021e2f4e594 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/ConsoleLogListener.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/ConsoleLogListener.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if !NetCore namespace Microsoft.DocAsCode.Common { using System; @@ -72,5 +71,4 @@ private ConsoleColor GetConsoleColor(LogLevel level) } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Microsoft.DocAsCode.Common/Loggers/CrossAppDomainListener.cs b/src/Microsoft.DocAsCode.Common/Loggers/CrossAppDomainListener.cs index 56c778c5127..60a55dba964 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/CrossAppDomainListener.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/CrossAppDomainListener.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if !NetCore namespace Microsoft.DocAsCode.Common { using System; @@ -35,5 +34,4 @@ public void Flush() Logger.Flush(); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Microsoft.DocAsCode.Common/Loggers/HtmlLogListener.cs b/src/Microsoft.DocAsCode.Common/Loggers/HtmlLogListener.cs index 4e8d7aa2bf5..54310fcd53a 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/HtmlLogListener.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/HtmlLogListener.cs @@ -18,7 +18,6 @@ public sealed class HtmlLogListener : ILoggerListener private static readonly Regex EscapeWithEncode = new Regex("&", RegexOptions.Compiled); private static readonly Regex EscapeWithoutEncode = new Regex(@"&(?!#?\w+;)", RegexOptions.Compiled); -#if !NetCore public HtmlLogListener(string reportPath) { var dir = Path.GetDirectoryName(reportPath); @@ -29,7 +28,6 @@ public HtmlLogListener(string reportPath) _writer = new StreamWriter(reportPath, true); WriteCommonHeader(); } -#endif public HtmlLogListener(StreamWriter writer) { diff --git a/src/Microsoft.DocAsCode.Common/Loggers/Logger.cs b/src/Microsoft.DocAsCode.Common/Loggers/Logger.cs index 573712c7a45..be677a67fa0 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/Logger.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/Logger.cs @@ -135,20 +135,12 @@ public static void Log(LogLevel level, string message, string phase = null, stri { Log(new LogItem { -#if NetCore - File = file, -#else File = file ?? LoggerFileScope.GetFileName(), -#endif Line = line, LogLevel = level, Message = message, Code = code, -#if NetCore - Phase = phase, -#else Phase = phase ?? LoggerPhaseScope.GetPhaseName(), -#endif }); } @@ -156,20 +148,12 @@ public static ILogItem GetLogItem(LogLevel level, string message, string phase = { return new LogItem { -#if NetCore - File = file, -#else File = file ?? LoggerFileScope.GetFileName(), -#endif Line = line, LogLevel = level, Message = message, Code = code, -#if NetCore - Phase = phase, -#else Phase = phase ?? LoggerPhaseScope.GetPhaseName(), -#endif }; } @@ -248,9 +232,7 @@ public static void Flush() _asyncListener.Flush(); } -#if !NetCore [Serializable] -#endif private class LogItem : ILogItem { public string File { get; set; } diff --git a/src/Microsoft.DocAsCode.Common/Loggers/LoggerFileScope.cs b/src/Microsoft.DocAsCode.Common/Loggers/LoggerFileScope.cs index 002f977fea6..1ce7ac7f552 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/LoggerFileScope.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/LoggerFileScope.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if !NetCore namespace Microsoft.DocAsCode.Common { using System; @@ -54,5 +53,4 @@ private sealed class CapturedLoggerFileScope public string FileName { get; } = GetFileName(); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Microsoft.DocAsCode.Common/Loggers/PerformanceScope.cs b/src/Microsoft.DocAsCode.Common/Loggers/PerformanceScope.cs index 473060693cd..adaf0718064 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/PerformanceScope.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/PerformanceScope.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if !NetCore namespace Microsoft.DocAsCode.Common { using System; @@ -49,5 +48,4 @@ private static string GetContent(string content, TimeSpan span) return $"Completed {content} in {span.TotalMilliseconds} milliseconds."; } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Microsoft.DocAsCode.Common/Loggers/ReplayLogListener.cs b/src/Microsoft.DocAsCode.Common/Loggers/ReplayLogListener.cs index f82d53ae72b..1cf0ca9f4a5 100644 --- a/src/Microsoft.DocAsCode.Common/Loggers/ReplayLogListener.cs +++ b/src/Microsoft.DocAsCode.Common/Loggers/ReplayLogListener.cs @@ -7,11 +7,7 @@ namespace Microsoft.DocAsCode.Common using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -#if NetCore - using ReplayList = System.Collections.Generic.SortedDictionary>; -#else - using ReplayList = System.Collections.Generic.SortedList>; -#endif + /// /// Replay log on flushing. /// @@ -19,7 +15,7 @@ namespace Microsoft.DocAsCode.Common public class ReplayLogListener : ILoggerListener { private readonly LogLevel _replayLevel; - private readonly ReplayList _replayList; + private readonly SortedList> _replayList; private ImmutableArray _listeners = ImmutableArray.Empty; @@ -28,7 +24,7 @@ public class ReplayLogListener : ILoggerListener public ReplayLogListener(LogLevel replayLevel = LogLevel.Warning) { _replayLevel = replayLevel; - _replayList = new ReplayList(); + _replayList = new SortedList>(); for (LogLevel level = replayLevel; level <= LogLevel.Error; level++) { _replayList.Add(level, new List()); @@ -102,17 +98,14 @@ private void WriteHeader(BuildStatus status) default: break; } -#if !NetCore + WriteToConsole(message, status); -#endif } private void WriteFooter(BuildStatus status) { var footer = string.Join(Environment.NewLine, _replayList.Select(s => $"\t{s.Value.Count} {s.Key}(s)")); -#if !NetCore WriteToConsole(footer, status); -#endif } private void WriteLineCore(ILogItem item) @@ -123,7 +116,6 @@ private void WriteLineCore(ILogItem item) } } -#if !NetCore private static void WriteToConsole(string message, BuildStatus status) { switch (status) @@ -144,7 +136,6 @@ private static void WriteToConsole(string message, ConsoleColor color = ConsoleC { ConsoleUtility.WriteLine(message, color); } -#endif private static BuildStatus GetBuildStatusFromLogLevel(LogLevel level) { diff --git a/src/Microsoft.DocAsCode.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs b/src/Microsoft.DocAsCode.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs index 7ee454361a6..07101f7322a 100644 --- a/src/Microsoft.DocAsCode.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs +++ b/src/Microsoft.DocAsCode.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs @@ -7,9 +7,7 @@ namespace Microsoft.DocAsCode.YamlSerialization.ObjectGraphTraversalStrategies using System.Collections; using System.Collections.Generic; using System.ComponentModel; -#if !NetCore using System.Globalization; -#endif using System.Reflection; using System.Reflection.Emit; From a7c61726e8104b1d58af5c26a2a0229caa2aa413 Mon Sep 17 00:00:00 2001 From: Thomas Ibel Date: Fri, 2 Dec 2022 17:49:42 +0100 Subject: [PATCH 2/2] apply changes from yufeih/net6test --- src/docfx/SubCommands/BuildCommand.cs | 8 ++++++++ src/docfx/SubCommands/DocumentBuilderWrapper.cs | 9 +++++++-- src/docfx/docfx.csproj | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/docfx/SubCommands/BuildCommand.cs b/src/docfx/SubCommands/BuildCommand.cs index 1e46a1b72cc..50e3e29afc2 100644 --- a/src/docfx/SubCommands/BuildCommand.cs +++ b/src/docfx/SubCommands/BuildCommand.cs @@ -503,6 +503,7 @@ private void BuildDocument(string baseDirectory, string outputDirectory) } } +#if NET472 private static void BuildDocumentWithPlugin(BuildJsonConfig config, TemplateManager manager, string baseDirectory, string outputDirectory, string applicationBaseDirectory, string pluginDirectory, string templateDirectory) { AppDomain builderDomain = null; @@ -531,6 +532,13 @@ private static void BuildDocumentWithPlugin(BuildJsonConfig config, TemplateMana } } } +#else + private static void BuildDocumentWithPlugin(BuildJsonConfig config, TemplateManager manager, string baseDirectory, string outputDirectory, string applicationBaseDirectory, string pluginDirectory, string templateDirectory) + { + var wrapper = new DocumentBuilderWrapper(config, manager, baseDirectory, outputDirectory, pluginDirectory, new CrossAppDomainListener(), templateDirectory); + wrapper.BuildDocument(); + } +#endif #endregion } diff --git a/src/docfx/SubCommands/DocumentBuilderWrapper.cs b/src/docfx/SubCommands/DocumentBuilderWrapper.cs index 2c42971d280..ef2d58b50b9 100644 --- a/src/docfx/SubCommands/DocumentBuilderWrapper.cs +++ b/src/docfx/SubCommands/DocumentBuilderWrapper.cs @@ -9,7 +9,6 @@ namespace Microsoft.DocAsCode.SubCommands using System.IO; using System.Linq; using System.Net; - using System.Runtime.Remoting.Lifetime; using System.Reflection; using System.Threading; @@ -67,7 +66,9 @@ public DocumentBuilderWrapper( public void BuildDocument() { - var sponsor = new ClientSponsor(); +#if NET472 + var sponsor = new System.Runtime.Remoting.Lifetime.ClientSponsor(); +#endif EnvironmentContext.SetBaseDirectory(_baseDirectory); EnvironmentContext.SetGitFeaturesDisabled(_disableGitFeatures); EnvironmentContext.SetVersion(_version); @@ -75,7 +76,9 @@ public void BuildDocument() { Logger.LogLevelThreshold = _logLevel; Logger.RegisterListener(_listener); +#if NET472 sponsor.Register(_listener); +#endif } try { @@ -106,7 +109,9 @@ public void BuildDocument() } finally { +#if NET472 sponsor.Close(); +#endif } } diff --git a/src/docfx/docfx.csproj b/src/docfx/docfx.csproj index b7c9a797f47..4687b55b8dd 100644 --- a/src/docfx/docfx.csproj +++ b/src/docfx/docfx.csproj @@ -1,5 +1,5 @@  - + Exe Generates documentation directly from source code and MarkDown files