![]() |
VOOZH | about |
dotnet add package Ecng.Licensing --version 1.0.74
NuGet\Install-Package Ecng.Licensing -Version 1.0.74
<PackageReference Include="Ecng.Licensing" Version="1.0.74" />
<PackageVersion Include="Ecng.Licensing" Version="1.0.74" />Directory.Packages.props
<PackageReference Include="Ecng.Licensing" />Project file
paket add Ecng.Licensing --version 1.0.74
#r "nuget: Ecng.Licensing, 1.0.74"
#:package Ecng.Licensing@1.0.74
#addin nuget:?package=Ecng.Licensing&version=1.0.74Install as a Cake Addin
#tool nuget:?package=Ecng.Licensing&version=1.0.74Install as a Cake Tool
A lightweight licensing library for .NET applications supporting license validation, expiration management, and multi-platform licensing.
Ecng.Licensing provides a simple and flexible licensing system for commercial .NET applications. It handles license parsing, validation, feature management, and expiration policies across multiple platforms (Windows, Linux, macOS).
Add a reference to the Ecng.Licensing package in your project.
A license contains:
Each feature has:
using Ecng.Licensing;
using System.IO;
// Load license from file
byte[] licenseData = File.ReadAllBytes("license.lic");
var license = new License("license.lic", licenseData);
Console.WriteLine($"License ID: {license.Id}");
Console.WriteLine($"Issued To: {license.IssuedTo}");
Console.WriteLine($"Issued Date: {license.IssuedDate}");
using Ecng.Licensing;
// Load license from embedded resource or byte array
byte[] licenseBytes = GetLicenseFromResource();
var license = new License(licenseBytes);
using Ecng.Licensing;
using System.Runtime.InteropServices;
// Get features for the current platform
var currentPlatform = OSPlatform.Windows; // or OSPlatform.Linux, OSPlatform.OSX
if (license.Features.TryGetValue(currentPlatform, out var features))
{
foreach (var feature in features)
{
Console.WriteLine($"Feature: {feature.Name}");
Console.WriteLine($"Expires: {feature.ExpirationDate}");
Console.WriteLine($"Action on expire: {feature.ExpireAction}");
if (!string.IsNullOrEmpty(feature.HardwareId))
Console.WriteLine($"Hardware ID: {feature.HardwareId}");
if (!string.IsNullOrEmpty(feature.Account))
Console.WriteLine($"Account: {feature.Account}");
}
}
using Ecng.Licensing;
using System.Linq;
using System.Runtime.InteropServices;
public bool IsFeatureAvailable(License license, string featureName)
{
var currentPlatform = OSPlatform.Windows;
if (!license.Features.TryGetValue(currentPlatform, out var features))
return false;
var feature = features.FirstOrDefault(f => f.Name == featureName);
if (feature == null)
return false;
// Check if feature has expired
if (DateTime.UtcNow > feature.ExpirationDate)
{
if (feature.ExpireAction == LicenseExpireActions.PreventWork)
return false;
}
return true;
}
// Usage
if (IsFeatureAvailable(license, "Trading"))
{
Console.WriteLine("Trading feature is available");
}
using Ecng.Licensing;
using System.Linq;
using System.Runtime.InteropServices;
public bool ValidateHardwareId(License license, string currentHardwareId)
{
var currentPlatform = OSPlatform.Windows;
if (!license.Features.TryGetValue(currentPlatform, out var features))
return false;
// If any feature has a hardware ID, validate it
var featuresWithHwId = features.Where(f => !string.IsNullOrEmpty(f.HardwareId));
if (!featuresWithHwId.Any())
return true; // No hardware binding
return featuresWithHwId.Any(f => f.HardwareId.Equals(currentHardwareId,
StringComparison.OrdinalIgnoreCase));
}
using Ecng.Licensing;
using System.Linq;
public class LicenseStatus
{
public bool IsValid { get; set; }
public bool IsExpired { get; set; }
public DateTime? ExpirationDate { get; set; }
public LicenseExpireActions? ExpireAction { get; set; }
}
public LicenseStatus GetLicenseStatus(License license, string featureName)
{
var currentPlatform = System.Runtime.InteropServices.OSPlatform.Windows;
var status = new LicenseStatus { IsValid = false };
if (!license.Features.TryGetValue(currentPlatform, out var features))
return status;
var feature = features.FirstOrDefault(f => f.Name == featureName);
if (feature == null)
return status;
status.ExpirationDate = feature.ExpirationDate;
status.ExpireAction = feature.ExpireAction;
status.IsExpired = DateTime.UtcNow > feature.ExpirationDate;
status.IsValid = !status.IsExpired ||
feature.ExpireAction == LicenseExpireActions.PreventUpgrade;
return status;
}
// Usage
var status = GetLicenseStatus(license, "Analytics");
if (status.IsExpired)
{
Console.WriteLine($"License expired on {status.ExpirationDate}");
Console.WriteLine($"Action: {status.ExpireAction}");
}
using Ecng.Licensing;
using System.Linq;
using System.Runtime.InteropServices;
public class LicenseManager
{
private readonly License _license;
private readonly OSPlatform _platform;
public LicenseManager(License license)
{
_license = license;
_platform = GetCurrentPlatform();
}
private OSPlatform GetCurrentPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return OSPlatform.Windows;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return OSPlatform.Linux;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return OSPlatform.OSX;
throw new PlatformNotSupportedException();
}
public bool HasFeature(string featureName)
{
if (!_license.Features.TryGetValue(_platform, out var features))
return false;
return features.Any(f => f.Name.Equals(featureName,
StringComparison.OrdinalIgnoreCase));
}
public IEnumerable<string> GetActiveFeatures()
{
if (!_license.Features.TryGetValue(_platform, out var features))
return Enumerable.Empty<string>();
return features
.Where(f => DateTime.UtcNow <= f.ExpirationDate ||
f.ExpireAction == LicenseExpireActions.PreventUpgrade)
.Select(f => f.Name);
}
public IEnumerable<LicenseFeature> GetExpiringFeatures(int daysAhead)
{
if (!_license.Features.TryGetValue(_platform, out var features))
return Enumerable.Empty<LicenseFeature>();
var threshold = DateTime.UtcNow.AddDays(daysAhead);
return features.Where(f =>
f.ExpirationDate > DateTime.UtcNow &&
f.ExpirationDate <= threshold);
}
}
// Usage
var manager = new LicenseManager(license);
// Check if feature exists
if (manager.HasFeature("Trading"))
{
Console.WriteLine("Trading feature is licensed");
}
// Get all active features
foreach (var feature in manager.GetActiveFeatures())
{
Console.WriteLine($"Active feature: {feature}");
}
// Get features expiring in next 30 days
foreach (var feature in manager.GetExpiringFeatures(30))
{
Console.WriteLine($"Feature {feature.Name} expires on {feature.ExpirationDate}");
}
using Ecng.Licensing;
// Access basic license information
Console.WriteLine($"License Version: {license.Version}");
Console.WriteLine($"License ID: {license.Id}");
Console.WriteLine($"Issued To: {license.IssuedTo}");
Console.WriteLine($"Issued Date: {license.IssuedDate:yyyy-MM-dd}");
// Access raw license data
byte[] originalBody = license.Body;
byte[] bodyWithoutSignature = license.BodyWithoutSignature;
byte[] signature = license.Signature;
// Get string representation
string licenseInfo = license.ToString(); // Returns "N{Id} ({HardwareId})"
The LicenseExpireActions enum defines what happens when a license expires:
using Ecng.Licensing;
public void HandleExpiration(LicenseFeature feature)
{
switch (feature.ExpireAction)
{
case LicenseExpireActions.PreventWork:
Console.WriteLine("Feature will stop working after expiration");
// Disable feature completely
break;
case LicenseExpireActions.PreventUpgrade:
Console.WriteLine("Feature will continue working but no updates allowed");
// Allow current version usage only
break;
}
}
Supports Windows, Linux, and macOS platforms.
Licenses are stored in XML format with the following structure:
<license>
<ver>1.0</ver>
<id>12345</id>
<issuedTo>user@example.com</issuedTo>
<issuedDate>20240101 00:00:00</issuedDate>
<platforms>
<platform name="Windows">
<feature name="Trading" expire="20251231 23:59:59" expireAction="PreventWork" hardwareId="" account="" />
<feature name="Analytics" expire="20251231 23:59:59" expireAction="PreventUpgrade" hardwareId="" account="" />
</platform>
</platforms>
<signature>BASE64_SIGNATURE</signature>
</license>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. 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 was computed. 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 was computed. 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. |
Showing the top 2 NuGet packages that depend on Ecng.Licensing:
| Package | Downloads |
|---|---|
|
StockSharp.Licensing
Licensing components. More info on web site https://stocksharp.com/store/ |
|
|
StockSharp.Web.DomainModel
StockSharp WebApi |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.74 | 52 | 6/17/2026 |
| 1.0.73 | 97 | 6/12/2026 |
| 1.0.72 | 201 | 5/15/2026 |
| 1.0.71 | 93 | 5/14/2026 |
| 1.0.70 | 103 | 5/3/2026 |
| 1.0.69 | 136 | 4/14/2026 |
| 1.0.68 | 132 | 3/17/2026 |
| 1.0.67 | 119 | 3/17/2026 |
| 1.0.66 | 116 | 3/15/2026 |
| 1.0.65 | 845 | 3/3/2026 |
| 1.0.64 | 114 | 2/28/2026 |
| 1.0.63 | 513 | 2/10/2026 |
| 1.0.62 | 378 | 2/4/2026 |
| 1.0.61 | 344 | 2/1/2026 |
| 1.0.60 | 116 | 1/26/2026 |
| 1.0.59 | 114 | 1/22/2026 |
| 1.0.58 | 120 | 1/19/2026 |
| 1.0.57 | 119 | 1/19/2026 |
| 1.0.56 | 127 | 1/18/2026 |
| 1.0.55 | 121 | 1/18/2026 |