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
<PackageReference Include="R3E.Compiler.CSharp" Version="1.0.2" />
<PackageVersion Include="R3E.Compiler.CSharp" Version="1.0.2" />
<PackageReference Include="R3E.Compiler.CSharp" />
paket add R3E.Compiler.CSharp --version 1.0.2
#r "nuget: R3E.Compiler.CSharp, 1.0.2"
#:package R3E.Compiler.CSharp@1.0.2
#addin nuget:?package=R3E.Compiler.CSharp&version=1.0.2
#tool nuget:?package=R3E.Compiler.CSharp&version=1.0.2
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 | Versions 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. |
-
net9.0
- Microsoft.CodeAnalysis.CSharp (>= 4.14.0)
- Neo (>= 1.0.2)
- Neo.Extensions (>= 1.0.2)
- R3E.SmartContract.Framework (>= 1.0.2)
- R3E.SmartContract.Testing (>= 1.0.2)
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.