Fabulous.AST.Build 2.0.0-pre08

This is a prerelease version of Fabulous.AST.Build.
dotnet add package Fabulous.AST.Build --version 2.0.0-pre08
                    
NuGet\Install-Package Fabulous.AST.Build -Version 2.0.0-pre08
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fabulous.AST.Build" Version="2.0.0-pre08">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fabulous.AST.Build" Version="2.0.0-pre08" />
                    
Directory.Packages.props
<PackageReference Include="Fabulous.AST.Build">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fabulous.AST.Build --version 2.0.0-pre08
                    
#r "nuget: Fabulous.AST.Build, 2.0.0-pre08"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fabulous.AST.Build@2.0.0-pre08
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fabulous.AST.Build&version=2.0.0-pre08&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Fabulous.AST.Build&version=2.0.0-pre08&prerelease
                    
Install as a Cake Tool

Fabulous.AST.Build

Automatically generate F# types from JSON files at build time.

Overview

Fabulous.AST.Build is an MSBuild task that:

  • Watches JSON files in your project
  • Automatically generates F# record types during build
  • Supports incremental builds (only regenerates when JSON changes)
  • Integrates seamlessly with MSBuild and .NET CLI

Use cases:

  • Generate F# types from API response samples
  • Keep type definitions in sync with JSON schemas
  • Automate type generation in CI/CD pipelines

💡 Tip: For programmatic control over generation, use Fabulous.AST.Json directly.

Installation

dotnet add package Fabulous.AST.Build

Requirements: .NET 8.0 or later

Tutorial

Step 1: Create a JSON Schema File

Create a folder for your JSON schemas and add a sample file.

schemas/user.json:

{
    "id": 1,
    "name": "Alice",
    "email": "alice@example.com",
    "isActive": true
}

Step 2: Configure Your Project

Add the FabulousAstJson item to your .fsproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Fabulous.AST.Build" Version="2.0.0" />
  </ItemGroup>

  
  <ItemGroup>
    <FabulousAstJson Include="schemas/user.json" />
  </ItemGroup>
</Project>

Note: Generated files are automatically included in compilation. No manual <Compile Include="..."> is needed.

Step 3: Build Your Project

dotnet build

This generates Generated/user.Generated.fs:

// Auto-generated from schemas/user.json
// Hash: abc123...
// Do not edit manually - changes will be overwritten

type User = {
    id: int
    name: string
    email: string
    isActive: bool
}

Step 4: Custom Root Type Name

By default, the root type name is derived from the filename. Override it with RootName:

<ItemGroup>
  <FabulousAstJson Include="schemas/api-response.json" RootName="ApiResponse" />
</ItemGroup>

Step 5: Add a Module

Wrap generated types in a file-level module using ModuleName:

<ItemGroup>
  <FabulousAstJson Include="schemas/user.json"
                   RootName="User"
                   ModuleName="MyApp.Models" />
</ItemGroup>

Output:

module MyApp.Models

type User = {
    id: int
    name: string
    email: string
    isActive: bool
}

Step 6: Multiple JSON Files

Process multiple schemas with different configurations:

<ItemGroup>
  <FabulousAstJson Include="schemas/user.json"
                   RootName="User"
                   ModuleName="MyApp.Models.User" />
  <FabulousAstJson Include="schemas/product.json"
                   RootName="Product"
                   ModuleName="MyApp.Models.Product" />
  <FabulousAstJson Include="schemas/order.json"
                   RootName="CustomerOrder"
                   ModuleName="MyApp.Orders" />
</ItemGroup>

Note: Each file must have a unique module name since file-level modules cannot share the same fully-qualified name.

Step 7: Custom Output Directory

Change where generated files are placed:

<PropertyGroup>
  <FabulousAstOutputFolder>Types</FabulousAstOutputFolder>
</PropertyGroup>

Step 8: Glob Patterns

Process all JSON files in a directory:

<ItemGroup>
  <FabulousAstJson Include="schemas/**/*.json" />
</ItemGroup>

Step 9: Custom Output Filename

Override the default {filename}.Generated.fs pattern:

<ItemGroup>
  <FabulousAstJson Include="schemas/user.json"
                   OutputFileName="UserTypes.fs" />
</ItemGroup>

Configuration Reference

Project Properties

Property Default Description
FabulousAstOutputFolder Generated Output folder for generated files (relative to project directory)
EnableFabulousAstJson true Enable/disable generation (useful for CI)

Item Metadata

Metadata Default Description
RootName Root Name of the root type
ModuleName (empty) File-level module name (e.g., MyApp.Models)
OutputFileName {InputName}.g.fs Custom output filename

Type Inference

The generator infers F# types from JSON values:

JSON Value F# Type
"string" string
123 int
9999999999 int64
123.45 float
true/false bool
null obj
[...] ElementType list
{...} Record type

Arrays Become List Types

Input (users.json):

[
    { "id": 1, "name": "Alice" },
    { "id": 2, "name": "Bob" }
]

Output:

type UsersItem = { id: int; name: string }
type Users = UsersItem list

Nested Objects Become Nested Types

Input (company.json):

{
    "name": "Acme Corp",
    "address": {
        "street": "123 Main St",
        "city": "London"
    }
}

Output:

type Address = { street: string; city: string }
type Company = { name: string; address: Address }

Optional Fields

Fields missing or null in some array objects become option types:

Input:

[
    { "id": 1, "name": "Alice", "nickname": "Ali" },
    { "id": 2, "name": "Bob" }
]

Output:

type RootItem = { id: int; name: string; nickname: string option }
type Root = RootItem list

Special Field Name Handling

Leading Digits

JSON fields starting with digits are prefixed with _:

{ "2faEnabled": true }

Generates:

type Root = { _2faEnabled: bool }

Reserved Keywords

F# keywords are escaped with double backticks:

{ "type": "admin", "class": "premium" }

Generates:

type Root = { ``type``: string; ``class``: string }

Incremental Builds

The task uses content hashing for smart rebuilds:

  • Files are only regenerated when JSON content changes
  • Configuration changes (RootName, ModuleName, etc.) trigger regeneration
  • Generated files include a hash comment for verification

IDE Integration

Generated files are automatically included in compilation and placed before your source files, ensuring proper compile order.

IDE Recognition

Since generated files are added at project load time, most IDEs will recognize them after the first build. If your IDE doesn't see the generated types:

  1. Build the project once (dotnet build)
  2. Reload/refresh the project in your IDE

Tips

  • Keep generated files in source control - Avoids first-build issues and ensures CI builds work immediately
  • Don't delete generated files - Incremental build only regenerates when JSON changes
  • Multi-targeting works automatically - Generation runs once before all target framework builds

Troubleshooting

IDE Not Seeing Generated Files

  1. Build the project: dotnet build
  2. Reload/refresh the project in your IDE
  3. Ensure the file exists in the Generated/ folder

Generated File Not Updating

dotnet clean && dotnet build

Disable Generation

<EnableFabulousAstJson>false</EnableFabulousAstJson>

Or via command line:

dotnet build -p:EnableFabulousAstJson=false
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-pre08 42 6/2/2026
2.0.0-pre07 56 5/30/2026
2.0.0-pre06 85 1/9/2026
2.0.0-pre05 214 12/19/2025
2.0.0-pre04 244 12/15/2025
2.0.0-pre03 143 12/13/2025
2.0.0-pre02 100 12/12/2025
2.0.0-pre01 87 12/12/2025

### Changed
- No changes