Search Results for

    JD.MSBuild.Fluent

    A strongly-typed, fluent DSL for authoring MSBuild packages in C#

    NuGet License CI codecov

    Author MSBuild .props, .targets, and SDK assets using a strongly-typed fluent API in C#, then automatically generate 100% standard MSBuild XML during build. No more hand-editing XML - write refactorable, testable, type-safe C# code instead.

    โœจ Features

    • ๐ŸŽฏ Strongly-typed fluent API - IntelliSense, refactoring, compile-time validation
    • ๐Ÿ”„ Automatic build integration - Generate MSBuild assets during dotnet build, no CLI required
    • ๐Ÿ“ฆ Full NuGet layout support - build/, buildTransitive/, and Sdk/ folders
    • ๐Ÿ”ง XML scaffolding - Convert existing XML to fluent code with jdmsbuild scaffold
    • โœ… Production-tested - Validated against real-world MSBuild packages
    • ๐Ÿ“ Deterministic output - Consistent XML generation for meaningful diffs

    Quick Start

    1. Install the package

    <PackageReference Include="JD.MSBuild.Fluent" Version="*" />
    

    2. Define your MSBuild assets in C#

    using JD.MSBuild.Fluent;
    using JD.MSBuild.Fluent.Fluent;
    
    namespace MySdk;
    
    public static class DefinitionFactory
    {
      public static PackageDefinition Create() => Package.Define("MySdk")
        .Props(p => p
          .Property("MySdkEnabled", "true")
          .Property("MySdkVersion", "1.0.0"))
        .Targets(t => t
          .Target("MySdk_Hello", target => target
            .BeforeTargets("Build")
            .Condition("'$(MySdkEnabled)' == 'true'")
            .Message("Hello from MySdk v$(MySdkVersion)!", "High")))
        .Pack(o => { 
          o.BuildTransitive = true; 
          o.EmitSdk = true; 
        })
        .Build();
    }
    

    3. Build your project

    MSBuild assets are automatically generated during build and packaged correctly:

    • โœ… build/MySdk.props
    • โœ… build/MySdk.targets
    • โœ… buildTransitive/MySdk.props and .targets
    • โœ… Sdk/MySdk/Sdk.props and Sdk.targets

    No CLI required! Just build and pack:

    dotnet build
    dotnet pack
    

    ๐ŸŽฏ Why JD.MSBuild.Fluent?

    Problem: Hand-editing MSBuild XML is painful

    • โŒ No IntelliSense or type safety
    • โŒ No refactoring support
    • โŒ Hard to test and validate
    • โŒ Copy-paste leads to duplication
    • โŒ Difficult to review diffs

    Solution: Write C# instead

    • โœ… Strongly-typed API with full IntelliSense
    • โœ… Refactoring support - rename, extract, move
    • โœ… Unit testable - validate logic before publishing
    • โœ… DRY principle - reuse patterns across targets
    • โœ… Better diffs - meaningful C# changes instead of XML noise
    • โœ… Automatic generation - integrated into build pipeline

    ๐Ÿ“š Documentation

    Getting Started

    • Introduction - Project overview and core concepts
    • Getting Started Guide - Installation and your first package
    • Examples - Real-world usage examples

    User Guides

    • Overview - Guide to all user documentation
    • Basic Concepts - Understanding the fluent API
    • MSBuild Integration - How build integration works
    • Migration from XML - Convert existing XML to fluent
    • Advanced Topics - Custom tasks, conditions, and more

    Reference

    • API Reference - Complete API documentation
    • CLI Reference - Command-line tool documentation

    ๐Ÿ”„ Migrate from XML

    Convert existing MSBuild XML files to fluent API:

    # Install CLI tool
    dotnet tool install -g JD.MSBuild.Fluent.Cli
    
    # Scaffold from existing XML
    jdmsbuild scaffold --xml MyPackage.targets --output DefinitionFactory.cs --package-id MyCompany.MyPackage
    

    See the Migration Guide for complete details.

    ๐Ÿงช Samples

    • Minimal SDK Package - Complete end-to-end example
    • Integration tests validate against JD.Efcpt.Build (real-world production package)

    ๐Ÿ—๏ธ Architecture Overview

    JD.MSBuild.Fluent has a clean, layered architecture:

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚     Fluent API (Builders)           โ”‚  โ† You work here
    โ”‚  Package.Define(...).Props().Build()โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚   Intermediate Representation (IR)  โ”‚  โ† Composable data structures
    โ”‚    MsBuildProject, MsBuildTarget    โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚         XML Renderer                โ”‚  โ† Deterministic serialization
    โ”‚     MsBuildXmlRenderer              โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚      Package Emitter                โ”‚  โ† NuGet folder layout
    โ”‚   build/, buildTransitive/, Sdk/    โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    

    Layers Explained

    1. Fluent API: High-level builders for natural C# authoring
    2. IR Layer: Immutable data structures representing MSBuild constructs
    3. Renderer: Converts IR to canonical MSBuild XML with deterministic ordering
    4. Emitter: Organizes rendered XML into NuGet package folder structure

    ๐Ÿค Contributing

    Contributions welcome! See our GitHub repository to get started.

    ๐Ÿ“„ License

    MIT License

    ๐Ÿ”— Related Projects

    • JD.Efcpt.Build - EF Core Power Tools build integration
    • JD.MSBuild.Containers - Docker container build integration
    • Edit this page
    In this article
    Back to top Generated by DocFX