WmiLightClassGenerator 1.0.404

There is a newer version of this package available.
See the version list below for details.
dotnet add package WmiLightClassGenerator --version 1.0.404
                    
NuGet\Install-Package WmiLightClassGenerator -Version 1.0.404
                    
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="WmiLightClassGenerator" Version="1.0.404">
  <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="WmiLightClassGenerator" Version="1.0.404" />
                    
Directory.Packages.props
<PackageReference Include="WmiLightClassGenerator">
  <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 WmiLightClassGenerator --version 1.0.404
                    
#r "nuget: WmiLightClassGenerator, 1.0.404"
                    
#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 WmiLightClassGenerator@1.0.404
                    
#: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=WmiLightClassGenerator&version=1.0.404
                    
Install as a Cake Addin
#tool nuget:?package=WmiLightClassGenerator&version=1.0.404
                    
Install as a Cake Tool

WmiLightClassGenerator

Build NuGet

Generates strongly-typed C# wrapper classes for Windows Management Instrumentation (WMI) classes using the WmiLight library.

Features

  • Generates strongly-typed C# wrapper classes from WMI class definitions
  • Auto-discovers enums from WMI ValueMap/Values qualifiers with inheritance chain traversal
  • Supports string-backed enums with [WmiValue] attributes and bidirectional conversion extensions
  • Generates static query helpers (GetInstances, GetByKey, FromPath, Where)
  • Fluent Builder pattern for embedded instance XML construction
  • Full XML documentation comments on all generated members
  • Handles WMI method parameters (in/out/ref) with proper typing
  • Reference class mappings for typed method return values
  • Configurable via JSON config file
  • Distributed as a build-only NuGet package (not added as a runtime dependency)

Getting Started

Installation

dotnet add package WmiLightClassGenerator

Since this is a build-only package, add PrivateAssets="all" to prevent it from becoming a transitive dependency:

<PackageReference Include="WmiLightClassGenerator" PrivateAssets="all" />

Your project will also need a reference to WmiLight for the generated code:

dotnet add package WmiLight

Configuration

Create a wmi-classes.json file in your project:

{
  "outputDirectory": "Generated",
  "namespace": "MyProject.Wmi",
  "classes": [
    {
      "wmiNamespace": "root\\cimv2",
      "wmiClassName": "Win32_OperatingSystem",
      "className": "OperatingSystem"
    }
  ]
}

Usage

Run the generator:

WmiLightClassGenerator.exe wmi-classes.json

Or, if the consuming project has a $(WmiLightClassGeneratorExe) MSBuild property available from the NuGet package:

$(WmiLightClassGeneratorExe) wmi-classes.json

This generates strongly-typed C# classes in the configured output directory.

Configuration Reference

Property Type Default Description
outputDirectory string "." Directory for generated files (relative to config file)
namespace string "MyProject.Wmi" C# namespace for generated code
classes array [] WMI classes to generate wrappers for
stringEnums array [] Custom string-backed enum definitions
propertyTypeOverrides object {} Map property names to custom enum types
enumRenames object {} Rename auto-discovered enums
referenceClassMappings object {} Map WMI reference class names to C# class names
additionalEnumValues object {} Merge additional values into auto-discovered enums

Class Definition

Property Required Description
wmiNamespace Yes WMI namespace (e.g., root\cimv2)
wmiClassName Yes WMI class name (e.g., Win32_OperatingSystem)
className No C# class name (auto-derived by stripping common prefixes like Win32_, Msvm_, CIM_)
outputFileName No Output file name (defaults to {className}.cs)

String Enum Definition

{
  "stringEnums": [
    {
      "name": "ExecutionState",
      "description": "The execution state of a managed element.",
      "values": {
        "Unknown": "Unknown",
        "Running": "Running",
        "Suspended": "Suspended"
      }
    }
  ]
}

Generated Code

The generator produces the following for each WMI class:

Infrastructure Files

The generator always emits these helper files that the generated code depends on: WmiValueAttribute, WqlWhereVisitor, WqlExpressionEvaluator, WmiPathParser, WmiDtdSerializer, WmiInstanceBuilder, WmiJobHelper.

Wrapper Classes

  • Read-only properties mapped to WMI properties with proper C# types
  • Instance and static methods with typed parameters
  • GetInstances(connection) — enumerate all WMI instances
  • GetByKey(connection, ...) — query by key properties
  • FromPath(connection, path) — resolve from WMI object path
  • Where(connection, predicate) — LINQ-style queries translated to WQL
  • Fluent Builder for embedded instance XML
  • IDisposable implementation

Enum Types

  • Integer-backed enums from WMI ValueMap/Values qualifiers with proper backing types
  • String-backed enums with [WmiValue] attributes and converter extension methods (ToWmiString(), To{EnumName}())
  • Auto-discovered from properties and method parameters with inheritance chain traversal

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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
1.0.407 74 4/7/2026
1.0.407-ci.2026-04-07T08-19... 34 4/7/2026
1.0.405 86 4/5/2026
1.0.405-ci.2026-04-05T20-44... 37 4/5/2026
1.0.404 86 4/4/2026