Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/instructions/default.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RefDocGen is a **reference documentation generator for .NET**, installed as a .N

## Tech Stack

- **.NET 8** (target framework: `net8.0`)
- **.NET 10** (target framework: `net10.0`)
- **C#** with nullable reference types enabled and implicit usings
- **Razor SDK** (`Microsoft.NET.Sdk.Razor`) — used for server-side HTML rendering via `HtmlRenderer`, not as a web app
- **Key libraries**: AngleSharp (HTML parsing), CommandLineParser (CLI), Markdig (Markdown), YamlDotNet (YAML config), Serilog (logging), Microsoft.Build (MSBuild integration)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
dotnet-version: 10.0.x

- name: Restore dependencies
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Default UI:
## Installation

Prerequisites:
- .NET 8 (or higher)
- .NET 10 (or higher)

Install as a .NET global tool from [NuGet](https://www.nuget.org/packages/RefDocGen):

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RefDocGen is a reference documentation generator for .NET.
## Installation

Prerequisites:
- .NET 8 (or higher)
- .NET 10 (or higher)

Install as a .NET global tool from [NuGet](https://www.nuget.org/packages/RefDocGen):

Expand Down
5 changes: 3 additions & 2 deletions src/RefDocGen/AssemblyAnalysis/AssemblyTypeExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using RefDocGen.CodeElements.Types.Concrete;
using RefDocGen.CodeElements.Types.Concrete.Delegate;
using RefDocGen.CodeElements.Types.Concrete.Enum;
using RefDocGen.Tools.Logging;
using RefDocGen.Tools.Exceptions;
using System.Reflection;

Expand Down Expand Up @@ -135,11 +136,11 @@ internal TypeRegistry GetDeclaredTypes()
types.AddRange(assembly.GetTypes());
includedAssemblies.Add(assemblyPath);

logger.LogInformation("Assembly {Name} loaded", assemblyPath);
RefDocGenLogMessages.LogAssemblyLoaded(logger, assemblyPath);
}
else
{
logger.LogInformation("Assembly {Name} excluded", assemblyPath);
RefDocGenLogMessages.LogAssemblyExcluded(logger, assemblyPath);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/RefDocGen/CodeElements/Members/Concrete/MethodData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal MethodData(
public bool IsFinal => MethodInfo.IsFinal;

/// <inheritdoc/>
public bool IsAsync => MethodInfo.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) != null;
public bool IsAsync => MethodInfo.GetCustomAttribute<AsyncStateMachineAttribute>() != null;

/// <inheritdoc/>
public bool IsSealed => OverridesAnotherMember && IsFinal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ParameterData(
public ITypeNameData Type { get; }

/// <inheritdoc/>
public bool IsParamsCollection => ParameterInfo.GetCustomAttribute(typeof(ParamArrayAttribute)) != null;
public bool IsParamsCollection => ParameterInfo.GetCustomAttribute<ParamArrayAttribute>() != null;

/// <inheritdoc/>
public bool IsInput => ParameterInfo.IsIn;
Expand Down
3 changes: 2 additions & 1 deletion src/RefDocGen/DocExtraction/DocCommentExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using RefDocGen.DocExtraction.Handlers.Types;
using RefDocGen.DocExtraction.InheritDoc;
using RefDocGen.DocExtraction.Tools;
using RefDocGen.Tools.Logging;
using RefDocGen.Tools.Xml;
using System.Xml.Linq;

Expand Down Expand Up @@ -133,7 +134,7 @@ internal void AddComments()
{
// load the document (preserve the whitespace, as the documentation is to be converted into HTML)
xmlDocument = XDocument.Load(xmlPath, LoadOptions.PreserveWhitespace);
logger.LogInformation("XML documentation file {Name} loaded", xmlPath);
RefDocGenLogMessages.LogXmlDocFileLoaded(logger, xmlPath);
}
catch (FileNotFoundException)
{
Expand Down
3 changes: 2 additions & 1 deletion src/RefDocGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using RefDocGen.TemplateProcessors.Default;
using RefDocGen.TemplateProcessors.Shared.Languages;
using RefDocGen.Tools.Exceptions;
using RefDocGen.Tools.Logging;
using Serilog;
using Serilog.Events;
using System.Globalization;
Expand Down Expand Up @@ -143,7 +144,7 @@ private static async Task Run(IProgramConfiguration config)
if (config.SaveConfig) // save the configuration
{
YamlFileConfiguration.SaveToFile(config);
logger.LogInformation("Configuration saved into {File} file", YamlFileConfiguration.FileName);
RefDocGenLogMessages.LogConfigurationSaved(logger, YamlFileConfiguration.FileName);
}

Console.WriteLine($"Documentation generated in the '{config.OutputDir}' folder");
Expand Down
24 changes: 12 additions & 12 deletions src/RefDocGen/RefDocGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisMode>recommended</AnalysisMode>
Expand All @@ -12,7 +12,7 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>refdocgen</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<Version>1.0.6</Version>
<Version>1.1.0</Version>
<Authors>Vojtěch Lengál</Authors>
<Title>RefDocGen</Title>
<Description>Reference Documentation Generator for .NET</Description>
Expand All @@ -24,22 +24,22 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.3.0" />
<PackageReference Include="AngleSharp" Version="1.4.0" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.11" />
<PackageReference Include="Microsoft.Build" Version="17.8.43" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.8.1" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="10.0.3" />
<PackageReference Include="Microsoft.Build" Version="18.3.3" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.11.2" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.103">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
<PackageReference Include="Markdig" Version="0.41.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.3" />
<PackageReference Include="Markdig" Version="1.1.0" />
<InternalsVisibleTo Include="RefDocGen.UnitTests" />
<InternalsVisibleTo Include="RefDocGen.IntegrationTests" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog" Version="4.3.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="YamlDotNet" Version="16.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ internal class DocCommentTransformer : IDocCommentTransformer
/// </summary>
private readonly IDocCommentHtmlConfiguration htmlConfiguration;

/// <inheritdoc cref="TypeUrlResolver"/>
private TypeUrlResolver? typeUrlResolver;

/// <inheritdoc cref="TypeRegistry"/>
private ITypeRegistry? typeRegistry;

Expand Down Expand Up @@ -89,8 +86,8 @@ public ITypeRegistry TypeRegistry
/// </summary>
private TypeUrlResolver TypeUrlResolver
{
get => typeUrlResolver ?? throw new InvalidOperationException("Type registry not provided");
set => typeUrlResolver = value;
get => field ?? throw new InvalidOperationException("Type registry not provided");
set;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ private void UpdateOlderPageVersions(string pagePath)

var versionList = document.GetElementById(versionListElementId);

if (versionList is not null)
{
versionList.InnerHtml = JsonSerializer.Serialize(versions); // add the current version to the 'Version list' element
}
_ = (versionList?.InnerHtml = JsonSerializer.Serialize(versions)); // add the current version to the 'Version list' element
Comment thread
VL-CZ marked this conversation as resolved.

File.WriteAllText(olderVersionFile, document.ToHtml()); // Write the updated HTML
}
Expand Down
27 changes: 22 additions & 5 deletions src/RefDocGen/TemplateProcessors/Shared/RazorTemplateProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using RefDocGen.TemplateProcessors.Shared.Tools;
using RefDocGen.Tools;
using RefDocGen.Tools.Exceptions;
using RefDocGen.Tools.Logging;

namespace RefDocGen.TemplateProcessors.Shared;

Expand Down Expand Up @@ -200,7 +201,10 @@ public void ProcessTemplates(ITypeRegistry typeRegistry, string outputDirectory,
_ = Directory.CreateDirectory(this.outputDirectory);
}

this.logger?.LogInformation("Generating documentation in {Folder} folder", this.outputDirectory);
if (this.logger is not null)
{
RefDocGenLogMessages.LogGeneratingDocumentation(this.logger, this.outputDirectory);
}

CopyStaticPages();

Expand Down Expand Up @@ -357,11 +361,17 @@ private void CopyStaticTemplateFilesDirectory()
if (staticFilesDir.Exists)
{
staticFilesDir.CopyTo(outputDirPath, true);
logger?.LogInformation("A directory containing static template data copied to {Directory}", outputDirPath);
if (logger is not null)
{
RefDocGenLogMessages.LogStaticTemplateDataCopied(logger, outputDirPath);
}
}
else
{
logger?.LogInformation("No directory containing static template data found at path {Directory}", staticFilesDir);
if (logger is not null)
{
RefDocGenLogMessages.LogNoStaticTemplateDataFound(logger, staticFilesDir.FullName);
}
}
}

Expand Down Expand Up @@ -430,7 +440,11 @@ private void CopyStaticPages()

foreach (var page in pages) // wrap each page in the static page template, process it, and copy it into the output directory
{
logger?.LogInformation("Static page {Path} found", Path.Combine(staticPagesDirectory, page.FullName));
if (logger is not null)
{
RefDocGenLogMessages.LogStaticPageFound(logger, staticPagesDirectory, page.FullName);
}

string outputPath = Path.Combine(outputDirectory, page.PageDirectory);

var paramDictionary = new Dictionary<string, object?>()
Expand Down Expand Up @@ -486,7 +500,10 @@ private void ProcessTemplate<TTemplate>(Dictionary<string, object?> customTempla
File.WriteAllText(outputFileName, html);
_ = pagesGenerated.Add(pagePath);

logger?.LogInformation("Page {Name} created", outputFileName);
if (logger is not null)
{
RefDocGenLogMessages.LogPageCreated(logger, outputFileName);
}
}
catch (Exception ex) // Template compilation failed -> delete the directory & throw an exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AngleSharp.Html.Dom;
using Markdig;
using Microsoft.Extensions.Logging;
using RefDocGen.Tools.Logging;
using RefDocGen.Tools.Exceptions;

namespace RefDocGen.TemplateProcessors.Shared.StaticPages;
Expand Down Expand Up @@ -120,7 +121,10 @@ internal void CopyNonPageFiles(string outputDirectory)
}

File.Copy(file.FullName, outputPath, true);
logger?.LogInformation("Static file {FilePath} copied to {OutputPath}", filePath, outputPath);
if (logger is not null)
{
RefDocGenLogMessages.LogStaticFileCopied(logger, filePath, outputPath);
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/RefDocGen/Tools/Logging/RefDocGenLogMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;

namespace RefDocGen.Tools.Logging;

/// <summary>
/// Source-generated logging methods used across the application.
/// </summary>
internal static partial class RefDocGenLogMessages
{
[LoggerMessage(Level = LogLevel.Information, Message = "Assembly {Name} loaded")]
internal static partial void LogAssemblyLoaded(ILogger logger, string name);

[LoggerMessage(Level = LogLevel.Information, Message = "Assembly {Name} excluded")]
internal static partial void LogAssemblyExcluded(ILogger logger, string name);

[LoggerMessage(Level = LogLevel.Information, Message = "XML documentation file {Name} loaded")]
internal static partial void LogXmlDocFileLoaded(ILogger logger, string name);

[LoggerMessage(Level = LogLevel.Information, Message = "Configuration saved into {File} file")]
internal static partial void LogConfigurationSaved(ILogger logger, string file);

[LoggerMessage(Level = LogLevel.Information, Message = "Generating documentation in {Folder} folder")]
internal static partial void LogGeneratingDocumentation(ILogger logger, string folder);

[LoggerMessage(Level = LogLevel.Information, Message = "A directory containing static template data copied to {Directory}")]
internal static partial void LogStaticTemplateDataCopied(ILogger logger, string directory);

[LoggerMessage(Level = LogLevel.Information, Message = "No directory containing static template data found at path {Directory}")]
internal static partial void LogNoStaticTemplateDataFound(ILogger logger, string directory);

[LoggerMessage(Level = LogLevel.Information, Message = "Static page {Directory}/{Page} found")]
internal static partial void LogStaticPageFound(ILogger logger, string directory, string page);

[LoggerMessage(Level = LogLevel.Information, Message = "Page {Name} created")]
internal static partial void LogPageCreated(ILogger logger, string name);

[LoggerMessage(Level = LogLevel.Information, Message = "Static file {FilePath} copied to {OutputPath}")]
internal static partial void LogStaticFileCopied(ILogger logger, string filePath, string outputPath);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<RootNamespace>RefDocGen.ExampleVbLibrary</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public void GenerateDoc()

var generator = new DocGenerator(
[
"../../../../RefDocGen.ExampleLibrary/bin/Debug/net8.0/RefDocGen.ExampleLibrary.dll", // ExampleLibrary
"../../../../RefDocGen.ExampleFSharpLibrary/bin/Debug/net8.0/RefDocGen.ExampleFSharpLibrary.dll", // ExampleFSharpLibrary
"../../../../RefDocGen.ExampleVbLibrary/bin/Debug/net8.0/RefDocGen.ExampleVbLibrary.dll", // ExampleVbLibrary
"../../../../RefDocGen.ExampleLibrary/bin/Debug/net10.0/RefDocGen.ExampleLibrary.dll", // ExampleLibrary
"../../../../RefDocGen.ExampleFSharpLibrary/bin/Debug/net10.0/RefDocGen.ExampleFSharpLibrary.dll", // ExampleFSharpLibrary
"../../../../RefDocGen.ExampleVbLibrary/bin/Debug/net10.0/RefDocGen.ExampleVbLibrary.dll", // ExampleVbLibrary
],
templateProcessor,
assemblyDataConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void GenerateDoc()
var logger = Substitute.For<ILogger>();

var generator = new DocGenerator(
["../../../../RefDocGen.ExampleLibrary/bin/Debug/net8.0/RefDocGen.ExampleLibrary.dll"], // use only the ExampleLibrary
["../../../../RefDocGen.ExampleLibrary/bin/Debug/net10.0/RefDocGen.ExampleLibrary.dll"], // use only the ExampleLibrary
templateProcessor,
assemblyDataConfig,
outputDir,
Expand Down
Loading