Neo.SmartContract.Analyzer
3.11.3
Prefix Reserved
dotnet add package Neo.SmartContract.Analyzer --version 3.11.3
NuGet\Install-Package Neo.SmartContract.Analyzer -Version 3.11.3
<PackageReference Include="Neo.SmartContract.Analyzer" Version="3.11.3" />
<PackageVersion Include="Neo.SmartContract.Analyzer" Version="3.11.3" />
<PackageReference Include="Neo.SmartContract.Analyzer" />
paket add Neo.SmartContract.Analyzer --version 3.11.3
#r "nuget: Neo.SmartContract.Analyzer, 3.11.3"
#:package Neo.SmartContract.Analyzer@3.11.3
#addin nuget:?package=Neo.SmartContract.Analyzer&version=3.11.3
#tool nuget:?package=Neo.SmartContract.Analyzer&version=3.11.3
Neo Smart Contract Roslyn Analyzers
Neo.SmartContract.Analyzer bundles Roslyn analyzers and code fixes that enforce NeoVM constraints, NEP standards, and high-signal best practices before you deploy a contract.
Highlights
- Type Safety – blocks unsupported primitives such as
float,double,decimal, riskySystem.Math/string/charhelpers, and unsafeBigIntegerconstruction. - BCL Guardrails – warns when contracts use LINQ, generic collections,
System.Diagnostics, or other runtime-only APIs. - Contract Shape – validates
SupportedStandards, method naming, event names, static-field initialization, and NEP boilerplate. - Error Handling – restricts multiple
catchblocks,ref/volatile, and suspect cast patterns so on-chain code stays deterministic.
Analyzer catalog
- BanCastMethodAnalyzer.cs – disallows unsupported cast helper methods that NeoVM cannot execute.
- BigIntegerCreationAnalyzer.cs – enforces safe
BigIntegerconstruction patterns. - BigIntegerUsageAnalyzer.cs – blocks unsupported
BigIntegerAPIs. - BigIntegerUsingUsageAnalyzer.cs – prevents using statements that dispose
BigIntegerin unsupported ways. - CatchOnlySystemExceptionAnalyzer.cs – constrains which exception types contracts can catch.
- CharMethodsUsageAnalyzer.cs – forbids
charhelpers that are not available on NeoVM. - CollectionTypesUsageAnalyzer.cs – blocks use of
List<T>,Dictionary<TKey,TValue>, and similar containers. - DecimalUsageAnalyzer.cs – rejects
decimal. - DoubleUsageAnalyzer.cs – rejects
double. - EnumMethodsUsageAnalyzer.cs – flags unsupported
Enumhelper calls. - FloatUsageAnalyzer.cs – rejects
float. - InitialValueAnalyzer.cs – suggests replacing InitialValue attributes with Parse-based initialization and warns when UInt160/UInt256/ECPoint are initialized without
Parse. - KeywordUsageAnalyzer.cs – guards against restricted C# keywords.
- LinqUsageAnalyzer.cs – disallows LINQ extension usage.
- MultipleCatchBlockAnalyzer.cs – restricts multiple
catchclauses in a singletry. - NepStandardAnalyzer.cs – validates
SupportedStandardsattribute content. - NepStandardImplementationAnalyzer.cs – verifies NEP interface implementations line up with declared standards.
- NotifyEventNameAnalyzer.cs – enforces consistent event names passed to
Notify. - RefKeywordUsageAnalyzer.cs – blocks
refusage in contracts. - SmartContractMethodNamingAnalyzer.cs – enforces allowed ABI method names.
- SmartContractMethodNamingAnalyzer.Underline.cs – forbids underscores in public contract methods.
- StaticFieldInitializationAnalyzer.cs – ensures static fields are initialized deterministically.
- StorageKeyCollisionAnalyzer.cs – warns when storage keys can collide across maps or direct storage access.
- StringBuilderUsageAnalyzer.cs – restricts
StringBuilderAPIs to supported members. - StringMethodUsageAnalyzer.cs – flags unsupported
stringhelpers. - SystemDiagnosticsUsageAnalyzer.cs – blocks
System.Diagnosticsusages. - SystemMathUsageAnalyzer.cs – blocks
System.Mathmembers that are not NeoVM friendly. - VolatileKeywordUsageAnalyzer.cs – rejects the
volatilekeyword.
Install
NuGet (recommended)
dotnet add package Neo.SmartContract.Analyzer --prerelease
or add to the project (or Directory.Build.props) and keep it private to the contract:
<ItemGroup>
<PackageReference Include="Neo.SmartContract.Analyzer" Version="*"
PrivateAssets="all"
IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>
Source reference
When the analyzer lives in the same repo, reference it directly so you can debug rules:
<ItemGroup>
<ProjectReference Include="..\path\to\Neo.SmartContract.Analyzer.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
Using the diagnostics
- Build or save the contract project—diagnostics show up in VS/VS Code,
dotnet build, and CI. - Treat analyzer output as build failures:
dotnet build /warnaserror
Add the following to .editorconfig to promote all seven shipped analyzer
categories (Usage, Syntax, Security, Naming, Type, Method, and
Namespace) to errors while keeping selected rules at a different severity:
[*.cs]
dotnet_analyzer_diagnostic.category-Usage.severity = error
dotnet_analyzer_diagnostic.category-Syntax.severity = error
dotnet_analyzer_diagnostic.category-Security.severity = error
dotnet_analyzer_diagnostic.category-Naming.severity = error
dotnet_analyzer_diagnostic.category-Type.severity = error
dotnet_analyzer_diagnostic.category-Method.severity = error
dotnet_analyzer_diagnostic.category-Namespace.severity = error
# Override individual rules after setting category defaults when needed.
dotnet_diagnostic.NC4014.severity = warning
- Only suppress warnings with
#pragma warning disablewhen you fully understand the trade-off.
CI tips
- Restore/install the analyzer before
dotnet build /warnaserrorso unsupported APIs never land ondev. - Upload build logs or SARIF reports so the whole team can track rule regressions.
Contributing
Add new rules, refine diagnostics, or update docs—just run dotnet test Neo.SmartContract.Analyzer.UnitTests before opening a PR.
License
MIT – see LICENSE.
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.