R3E.Compiler.CSharp 1.0.2

dotnet add package R3E.Compiler.CSharp --version 1.0.2
                    
NuGet\Install-Package R3E.Compiler.CSharp -Version 1.0.2
                    
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="R3E.Compiler.CSharp" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="R3E.Compiler.CSharp" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="R3E.Compiler.CSharp" />
                    
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 R3E.Compiler.CSharp --version 1.0.2
                    
#r "nuget: R3E.Compiler.CSharp, 1.0.2"
                    
#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 R3E.Compiler.CSharp@1.0.2
                    
#: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=R3E.Compiler.CSharp&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=R3E.Compiler.CSharp&version=1.0.2
                    
Install as a Cake Tool

R3E.Compiler.CSharp

Neo Smart Contract Compiler for C# - Compiles C# code to Neo VM bytecode.

Overview

R3E.Compiler.CSharp is the official C# compiler for Neo N3 smart contracts. It compiles C# source code into Neo VM bytecode, generating NEF (Neo Executable Format) files and contract manifests that can be deployed to the Neo blockchain.

Installation

As a NuGet Package (Library)

dotnet add package R3E.Compiler.CSharp

As a Global Tool

dotnet tool install -g R3E.Compiler.CSharp.Tool

Usage

As a Library

using Neo.Compiler;
using Microsoft.CodeAnalysis;

// Create compilation options
var options = new CompilationOptions
{
    Debug = CompilationOptions.DebugType.Extended,
    Optimize = CompilationOptions.OptimizationType.Basic,
    Nullable = NullableContextOptions.Enable
};

// Create compilation engine
var engine = new CompilationEngine(options);

// Compile from project file
var contexts = engine.CompileProject("MyContract.csproj");

// Or compile from source files
var contexts = engine.CompileSources("Contract1.cs", "Contract2.cs");

// Process results
foreach (var context in contexts)
{
    if (context.Success)
    {
        // Generate NEF, manifest, and debug info
        context.CreateResults("./output");
        
        Console.WriteLine($"Compiled {context.ContractName} successfully!");
    }
    else
    {
        // Handle compilation errors
        foreach (var diagnostic in context.Diagnostics)
        {
            Console.WriteLine(diagnostic);
        }
    }
}

Advanced Usage

// Compile with custom references
var references = new CompilationSourceReferences
{
    Packages = new[] 
    { 
        ("R3E.SmartContract.Framework", "3.9.0"),
        ("MyCustomPackage", "1.0.0")
    },
    Projects = new[] { "../SharedContracts/Shared.csproj" }
};

var contexts = engine.CompileSources(references, "MyContract.cs");

// Security analysis
foreach (var context in contexts.Where(c => c.Success))
{
    var nef = context.CreateExecutable();
    var manifest = context.CreateManifest();
    var debugInfo = context.CreateDebugInformation();
    
    SecurityAnalyzer.AnalyzeWithPrint(nef, manifest, debugInfo);
}

// Generate contract interface
var interfaceCode = ContractInterfaceGenerator.GenerateInterface(
    "MyContract", 
    manifest, 
    contractHash
);

Features

  • Full C# Language Support: Supports modern C# features compatible with Neo VM
  • Project and Source Compilation: Compile from .csproj files or individual source files
  • Optimization: Multiple optimization levels (None, Basic, Experimental, All)
  • Debug Information: Generate comprehensive debug information for debugging
  • Security Analysis: Built-in security analyzer to detect common vulnerabilities
  • Contract Interface Generation: Automatically generate C# interfaces for compiled contracts
  • Plugin Generation: Generate Neo node plugins from smart contracts
  • Artifact Generation: Flexible artifact generation options

Compilation Options

Option Description Default
Debug Debug information level (None, Strict, Extended) None
Optimize Optimization level (None, Basic, Experimental, All) None
Nullable Nullable context options Annotations
Checked Enable overflow/underflow checking false
NoInline Disable method inlining false
AddressVersion Neo address version byte 53 (0x35)

Output Files

The compiler generates the following files:

  • .nef - Neo Executable Format file containing the compiled bytecode
  • .manifest.json - Contract manifest with ABI, permissions, and metadata
  • .nefdbgnfo - Debug information for debugging tools
  • .abi.json - Application Binary Interface definition

Requirements

  • .NET 9.0 or higher
  • R3E.SmartContract.Framework reference in your smart contract project

Examples

See the examples directory for sample smart contracts and compilation scripts.

License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on R3E.Compiler.CSharp:

Package Downloads
R3E.SmartContract.Deploy

R3E Smart Contract Deploy v1.0.2 - Simplified deployment toolkit for Neo smart contracts. Features environment management, multi-contract deployment, verification tools, and deployment automation. Perfect for mainnet and testnet deployments

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 16 7/19/2025
1.0.1 44 7/18/2025
1.0.0 65 7/18/2025
0.0.4 119 7/14/2025
0.0.1 111 7/13/2025