Skip to content

Latest commit

 

History

History
149 lines (105 loc) · 3.98 KB

File metadata and controls

149 lines (105 loc) · 3.98 KB

Global Properties

Linqraft supports several MSBuild properties to customize code generation globally.

Available Properties

<Project>
  <PropertyGroup>
    <!-- Set namespace for DTOs in global namespace. Empty means use global namespace -->
    <LinqraftGlobalNamespace></LinqraftGlobalNamespace>

    <!-- Generate records instead of classes -->
    <LinqraftRecordGenerate>false</LinqraftRecordGenerate>

    <!-- Set property accessor pattern: Default, GetAndSet, GetAndInit, GetAndInternalSet -->
    <!-- Default is GetAndSet for classes, GetAndInit for records -->
    <LinqraftPropertyAccessor>Default</LinqraftPropertyAccessor>

    <!-- Add 'required' keyword on properties -->
    <LinqraftHasRequired>true</LinqraftHasRequired>

    <!-- Generate XML documentation comments -->
    <!-- All (summary+reference), SummaryOnly (summary only), None (no comments) -->
    <LinqraftCommentOutput>All</LinqraftCommentOutput>

    <!-- Remove nullability from array-type properties -->
    <LinqraftArrayNullabilityRemoval>true</LinqraftArrayNullabilityRemoval>

    <!-- Use hash-named namespace for nested DTOs (e.g., LinqraftGenerated_HASH.ItemsDto) -->
    <!-- When false, uses hash-suffixed class names (e.g., ItemsDto_HASH) -->
    <LinqraftNestedDtoUseHashNamespace>true</LinqraftNestedDtoUseHashNamespace>

    <!-- Add 'global using Linqraft;' to generated code for compatibility with v0.8.1 and earlier -->
    <LinqraftGlobalUsing>true</LinqraftGlobalUsing>
  </PropertyGroup>
</Project>

Property Details

LinqraftGlobalNamespace

Controls the namespace for DTOs when the source entity is in the global namespace.

<!-- Use global namespace (default) -->
<LinqraftGlobalNamespace></LinqraftGlobalNamespace>

<!-- Use specific namespace -->
<LinqraftGlobalNamespace>MyProject.Dtos</LinqraftGlobalNamespace>

LinqraftRecordGenerate

Generate records instead of classes:

<LinqraftRecordGenerate>true</LinqraftRecordGenerate>
// Generated as record
public partial record OrderDto
{
    public required int Id { get; init; }
    public required string CustomerName { get; init; }
    public required decimal TotalAmount { get; init; }
}

LinqraftPropertyAccessor

Control property accessor patterns:

  • Default: get; set; for classes, get; init; for records
  • GetAndSet: get; set;
  • GetAndInit: get; init;
  • GetAndInternalSet: get; internal set;
<LinqraftPropertyAccessor>GetAndInit</LinqraftPropertyAccessor>
public partial class OrderDto
{
    public required int Id { get; init; }
    public required string CustomerName { get; init; }
}

LinqraftHasRequired

Control the required keyword on properties:

<LinqraftHasRequired>false</LinqraftHasRequired>
public partial class OrderDto
{
    public int Id { get; set; } // No 'required' keyword
    public string CustomerName { get; set; }
}

LinqraftCommentOutput

See Auto-Generated Comments for details.

LinqraftArrayNullabilityRemoval

See Array Nullability Removal for details.

LinqraftNestedDtoUseHashNamespace

See Nested DTO Naming for details.

LinqraftGlobalUsing

Controls whether generated code includes global using Linqraft;.

<!-- Add the global using (default) -->
<LinqraftGlobalUsing>true</LinqraftGlobalUsing>

<!-- Opt out when you want to manage imports yourself -->
<LinqraftGlobalUsing>false</LinqraftGlobalUsing>

This is enabled by default to preserve compatibility with Linqraft v0.8.1 and earlier.

Viewing Generated Code

To inspect the generated code:

  1. F12 (Go to Definition) on the DTO class name
  2. Output to files by adding these settings:
<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

Generated files will be written to the Generated/ folder in your project.