using System; using System.IO; using System.Threading.Tasks; using System.Xml.Linq; namespace NetDocsForLLM.Helpers { public static class DocFxHelper { public static async Task CreateDocFxConfigAsync(string outputPath, params string[] assemblyPaths) { if (string.IsNullOrEmpty(outputPath)) throw new ArgumentException("Ruta de salida no válida", nameof(outputPath)); if (assemblyPaths == null || assemblyPaths.Length == 0) throw new ArgumentException("Debe proporcionar al menos una ruta de ensamblado", nameof(assemblyPaths)); var configPath = Path.Combine(outputPath, "docfx.json"); var config = GenerateDocFxConfigContent(assemblyPaths); try { await File.WriteAllTextAsync(configPath, config); return configPath; } catch (Exception ex) { throw new InvalidOperationException($"Error al crear configuración de DocFX: {ex.Message}", ex); } } private static string GenerateDocFxConfigContent(string[] assemblyPaths) { var files = string.Join("\",\n \"", assemblyPaths.Select(p => p.Replace("\\", "\\\\"))); return $@" {{ ""metadata"": [ {{ ""src"": [ {{ ""files"": [ ""{files}"" ], ""src"": ""."" }} ], ""dest"": ""obj/api"", ""properties"": {{ ""TargetFramework"": ""net6.0"" }}, ""disableGitFeatures"": true, ""disableDefaultFilter"": false }} ], ""build"": {{ ""content"": [ {{ ""files"": [""*.yml""], ""src"": ""obj/api"", ""dest"": ""api"" }} ], ""resource"": [ {{ ""files"": [""images/**""], ""exclude"": [""obj/**"", ""_site/**""] }} ], ""dest"": ""_site"", ""globalMetadataFiles"": [], ""fileMetadataFiles"": [], ""template"": [""default""], ""postProcessors"": [], ""markdownEngineName"": ""markdig"", ""noLangKeyword"": false, ""keepFileLink"": false, ""cleanupCacheHistory"": false, ""disableGitFeatures"": false }} }}"; } public static XDocument ParseXmlComments(string xmlPath) { if (string.IsNullOrEmpty(xmlPath) || !File.Exists(xmlPath)) return null; try { return XDocument.Load(xmlPath); } catch (Exception) { return null; } } } }