![]() |
VOOZH | about |
dotnet add package System.CodeDom --version 10.0.9
NuGet\Install-Package System.CodeDom -Version 10.0.9
<PackageReference Include="System.CodeDom" Version="10.0.9" />
<PackageVersion Include="System.CodeDom" Version="10.0.9" />Directory.Packages.props
<PackageReference Include="System.CodeDom" />Project file
paket add System.CodeDom --version 10.0.9
#r "nuget: System.CodeDom, 10.0.9"
#:package System.CodeDom@10.0.9
#addin nuget:?package=System.CodeDom&version=10.0.9Install as a Cake Addin
#tool nuget:?package=System.CodeDom&version=10.0.9Install as a Cake Tool
Provides functionality for dynamically generating and compiling source code using the Code Document Object Model (CodeDOM).
It allows developers to represent code in a language-agnostic format and then generate code in multiple languages, such as C# and VB.NET. The primary use cases include creating dynamic code generation tools, runtime code generation, and facilitating code analysis or transformation.
For a new modern development consider using the .NET Compiler Platform SDK, in particular Roslyn source generators.
Generating and compiling C# code:
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
// Create a new CodeCompileUnit to hold the code
var compileUnit = new CodeCompileUnit();
// Create a namespace
var codeNamespace = new CodeNamespace("MyNamespace");
compileUnit.Namespaces.Add(codeNamespace);
// Create a class
var classDeclaration = new CodeTypeDeclaration("MyClass")
{
IsClass = true
};
codeNamespace.Types.Add(classDeclaration);
// Add a simple method to the class
var method = new CodeMemberMethod
{
Name = "HelloWorld",
ReturnType = new CodeTypeReference(typeof(void)),
};
classDeclaration.Members.Add(method);
var methodInvocation = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("Console"),
"WriteLine",
new CodePrimitiveExpression("Hello, World!"));
method.Statements.Add(methodInvocation);
// Generate C# code from the CodeDOM structure
CodeDomProvider provider = new CSharpCodeProvider();
using (var writer = new StringWriter())
{
var codeGenereationOptions = new CodeGeneratorOptions()
{
BlankLinesBetweenMembers = false,
IndentString = " ",
};
provider.GenerateCodeFromCompileUnit(compileUnit, writer, codeGenereationOptions);
Console.WriteLine(writer.GetStringBuilder().ToString());
}
This example generates:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyNamespace {
public class MyClass {
private void HelloWorld() {
Console.WriteLine("Hello, World!");
}
}
}
The main types provided by this library are:
System.CodeDom.CodeObjectSystem.CodeDom.CodeCompileUnitSystem.CodeDom.CodeNamespaceSystem.CodeDom.CodeTypeDeclarationSystem.CodeDom.CodeMemberMethodSystem.CodeDom.CodeTypeReferenceSystem.CodeDom.CodeMethodInvokeExpressionSystem.CodeDom.CodeTypeReferenceExpressionSystem.CodeDom.CodePrimitiveExpressionSystem.CodeDom.Compiler.CodeDomProviderSystem.CodeDom.Compiler.CodeGeneratorOptionsMicrosoft.CSharp.CSharpCodeProviderMicrosoft.VisualBasic.VBCodeProviderSystem.CodeDom is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on System.CodeDom:
| Package | Downloads |
|---|---|
|
System.Management
Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. Commonly Used Types: System.Management.ManagementClass System.Management.ManagementObject System.Management.SelectQuery |
|
|
Mono.TextTemplating
Embeddable engine for the T4 templating language, a general-purpose way to generate text or code files using C# |
|
|
EntityFramework
Entity Framework 6 (EF6) is a tried and tested object-relational mapper for .NET with many years of feature development and stabilization. |
|
|
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild. |
|
|
Microsoft.Windows.Compatibility
This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard. |
Showing the top 20 popular GitHub repositories that depend on System.CodeDom:
| Repository | Stars |
|---|---|
|
dotnet/maui
.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
|
|
|
dotnet/roslyn
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
|
|
|
chocolatey/choco
Chocolatey - the package manager for Windows
|
|
|
dotnet/orleans
Cloud Native application framework for .NET
|
|
|
dotnet/machinelearning
ML.NET is an open source and cross-platform machine learning framework for .NET.
|
|
|
dotnet/wpf
WPF is a .NET Core UI framework for building Windows desktop applications.
|
|
|
PrismLibrary/Prism
Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, Xamarin Forms, and Uno / Win UI Applications..
|
|
|
Facepunch/sbox-public
s&box is a modern game engine, built on Valve's Source 2 and the latest .NET technology, it provides a modern intuitive editor for creating games
|
|
|
xamarin/Xamarin.Forms
Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
|
|
|
dotnet/msbuild
The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
|
|
|
Shane32/QRCoder
A pure C# Open Source QR Code implementation
|
|
|
akkadotnet/akka.net
Canonical actor model implementation for .NET with local + distributed actors in C# and F#.
|
|
|
tixl3d/tixl
TiXL is an open source software to create realtime motion graphics.
|
|
|
protobuf-net/protobuf-net
Protocol Buffers library for idiomatic .NET
|
|
|
dotnet/winforms
Windows Forms is a .NET UI framework for building Windows desktop applications.
|
|
|
Azure/azure-powershell
Microsoft Azure PowerShell
|
|
|
dotnetcore/FreeSql
.NET aot orm, VB.NET/C# orm, Mysql/PostgreSQL/SqlServer/Oracle orm, Sqlite/Firebird/Clickhouse/DuckDB orm, 达梦/金仓/虚谷/翰高/高斯 orm, 神通 orm, 南大通用 orm, 国产 orm, TDengine orm, QuestDB orm, MsAccess orm.
|
|
|
hardkoded/puppeteer-sharp
Headless Chrome .NET API
|
|
|
dotnet/sdk
Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
|
|
|
dotnet/macios
.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
|
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.0-preview.5.26302.115 | 1,207 | 6/9/2026 |
| 11.0.0-preview.4.26230.115 | 5,280 | 5/12/2026 |
| 11.0.0-preview.3.26207.106 | 5,160 | 4/14/2026 |
| 11.0.0-preview.2.26159.112 | 5,611 | 3/10/2026 |
| 11.0.0-preview.1.26104.118 | 7,154 | 2/10/2026 |
| 10.0.9 | 101,401 | 6/9/2026 |
| 10.0.8 | 520,690 | 5/12/2026 |
| 10.0.7 | 847,231 | 4/21/2026 |
| 10.0.6 | 235,877 | 4/14/2026 |
| 10.0.5 | 1,088,052 | 3/12/2026 |
| 10.0.4 | 139,942 | 3/10/2026 |
| 10.0.3 | 952,532 | 2/10/2026 |
| 10.0.2 | 1,939,894 | 1/13/2026 |
| 10.0.1 | 1,276,117 | 12/9/2025 |
| 9.0.17 | 5,111 | 6/9/2026 |
| 9.0.16 | 39,650 | 5/12/2026 |
| 9.0.15 | 115,156 | 4/14/2026 |
| 9.0.14 | 147,249 | 3/10/2026 |
| 9.0.13 | 75,748 | 2/10/2026 |
| 9.0.12 | 124,799 | 1/13/2026 |