Dependency licensing¶
This page sets the rules for adding and upgrading NuGet packages when licences or package holds are involved. It is written for engineers who change Directory.Packages.props, for those who run dependency upgrades, and for reviewers of those changes. Following it keeps a version bump from adding a commercial obligation or a runtime failure that the build does not show.
The upgrade policy and the list of holds are decided in ADR-0103. The default stack and its licence constraints are in ADR-0106. Where versions live is covered by Central package management.
Packages with a licence boundary¶
Several packages changed from an open source licence to a commercial one at a given major version, or need a licence key from a given version. These are the boundaries that ADR-0103 holds. A hold is revisited only when its reason is resolved.
| Package | Boundary | What ConnectSoft does |
|---|---|---|
AutoMapper |
Commercial from version 15 | Version 17 only where the licence key is wired. Repositories without the wiring stay on their current major. Mapster is the licence-free option. |
MassTransit* |
Version 9 needs MT_LICENSE |
Held at 9.2.6. New services use Orleans messaging. |
FluentAssertions |
Commercial from version 8 | Held at 7.2.2. Version 8 only where a licence is recorded. New tests use MSTest assertions. |
NServiceBus |
Commercial licence for production | Selectable in templates; production use needs a licence. |
SixLabors.ImageSharp |
Licence key from version 3.2 | Held at 3.1.12. |
Verify.* |
Newer versions add a sponsorship check that fails the build without a licence property | Held per repository. |
JsonSchema.Net |
Version 9 adds a maintenance fee with unclear terms | Held at 8.0.5. |
Rules¶
CS-DEP-001: Never cross a commercial licence boundary in a version bump¶
Severity: blocker · Applies to: service, library, api-client, blazor, template · Enforced by: manual · Status: active
Why¶
A bump across a licence boundary compiles and passes the tests. It still adds a commercial obligation that nobody approved, or a licence check that fails at runtime, for example a message bus that refuses to start without its licence variable. A template that crosses the boundary passes the obligation to every service generated from it.
Do¶
- Keep each package in the table above at its held version, or within its current major where the table says so.
- Treat a move across a licence boundary as a separate decision for the owner, recorded in ADR-0103, together with the licence wiring.
- When an upgrade tool proposes a held version, reject that proposal and leave the hold in place.
Don't¶
- Move
AutoMapperto version 15 or later in a repository without the licence wiring. - Move
MassTransit*above 9.2.6,FluentAssertionsto 8.x,SixLabors.ImageSharpto 3.2 or later, orJsonSchema.Netto 9.x. - Bump
Verify.*past the version held in the repository.
How to check¶
- A change to
Directory.Packages.propsdoes not move a package in the table above across its boundary. - The held lines keep their comment that cites the ADR (CS-DEP-013).
CS-DEP-002: Hold Swashbuckle and Microsoft.OpenApi together¶
Severity: blocker · Applies to: service, library, template · Enforced by: manual · Status: active
Why¶
Swashbuckle 11 needs Microsoft.OpenApi 3.x. The gRPC Swagger integration that services use, ServiceModel.Grpc.AspNetCore.Swashbuckle 1.26.0, throws MissingMethodException against OpenApi 3, so the Swagger document of a gRPC service returns HTTP 500. The code still compiles, and the default service model of the base template is gRPC.
Do¶
- Keep all
Swashbuckle.AspNetCore*packages at 10.3.1 andMicrosoft.OpenApiat 2.7.5. - Move them together, and together with
ConnectSoft.Extensions.Swagger, only after a newer gRPC Swashbuckle package supports OpenApi 3 and a host serves both the REST and the gRPC Swagger documents.
Don't¶
- Move one
Swashbuckle.AspNetCore.*package without the others. - Move
Microsoft.OpenApito 3.x.
How to check¶
Directory.Packages.props pins every Swashbuckle.AspNetCore* package at 10.3.1 and Microsoft.OpenApi at 2.7.5.
CS-DEP-003: Wire a commercial licence key through configuration¶
Severity: major · Applies to: service, library, template · Enforced by: manual · Status: active
Why¶
A licence key is not a credential, so it may be committed in appsettings*.json (see CS-SEC-001). How it is read still matters. Pipelines substitute JSON values only for keys that already exist in the file. Some libraries never validate the key at startup, so a service that starts proves nothing about whether the key was read.
Do¶
- Read the key from configuration, for example
AutoMapper:LicenseKey, with an environment variable as fallback. - Keep the key present in every
appsettingsvariant, so that a pipeline can overwrite it. - When the key is missing, log a warning and start without it.
- When you wire a key for the first time, prove the read path once: temporarily throw an exception that names the resolved value, boot one real host, then remove the probe.
Don't¶
- Stop the service when a licence key is missing.
- Assume the key is read because the service starts.
Example¶
string? licenseKey = configuration["AutoMapper:LicenseKey"]
?? Environment.GetEnvironmentVariable("AUTOMAPPER_LICENSE_KEY");
services.AddAutoMapper(options =>
{
if (!string.IsNullOrWhiteSpace(licenseKey))
{
options.LicenseKey = licenseKey;
}
});
How to check¶
- Every
appsettings*.jsonfile of the host contains the licence key setting. - The code reads it from configuration with a fallback and does not throw when it is missing.
CS-DEP-004: Check the licence of a package and of its later majors before you add it¶
Severity: major · Applies to: service, library, api-client, blazor, template · Enforced by: manual (target: ENF-009) · Status: active
Why¶
A package that is open source today can become commercial in its next major, as several of the packages above did. Adding it creates a future hold. A licence check before the package is added is cheaper than a hold discovered during an upgrade.
Do¶
- Before you add a package, read its licence on nuget.org and in its repository, and the licence of every later major version.
- Check its dependencies' licences too, for example with
nuget-licenseor the supply-chain licence gate. - When a package needs a commercial licence, record it as a hold in ADR-0103, with the reason, before the package is merged.
Don't¶
- Add a package whose licence is not on the allowed list of the licence gate without an owner decision.
- Add a package with a strong copyleft licence (GPL, AGPL, SSPL, EUPL, OSL).
How to check¶
- The change description names the licence of each new package.
- The supply-chain licence gate passes. Running it in every repository is tracked in ENF-009.
CS-DEP-005: Do not add Moq to new code¶
Severity: major · Applies to: service, library, api-client, blazor, template · Enforced by: manual (target: ENF-064) · Status: active
Why¶
Moq 4.20.0 shipped a build component that read the developer's Git e-mail address and sent a hash of it to a remote service. It was removed again, but it showed that the package's terms can change without notice. Most ConnectSoft test code already uses hand-written test doubles, which need no package and no licence decision.
Do¶
- Write hand-written fakes, stubs and spies, such as an in-memory repository or a fake that records its calls.
- When you change a test that uses Moq, replace the Moq setup in that test with a hand-written double. The templates move off Moq (ENF-064).
Don't¶
- Add a
Moqpackage reference to a project that does not have one. - Use Moq in new tests of a repository that already references it.
- Add another mocking library, such as NSubstitute or FakeItEasy, in its place.
Example¶
/// <summary>An in-memory order repository that records what was saved.</summary>
internal sealed class RecordingOrderRepository : IOrderRepository
{
private readonly List<Order> saved = [];
/// <summary>Gets the number of calls to <see cref="SaveAsync"/>.</summary>
public int SaveCalls { get; private set; }
/// <inheritdoc/>
public Task SaveAsync(Order order, CancellationToken cancellationToken)
{
this.SaveCalls++;
this.saved.Add(order);
return Task.CompletedTask;
}
}
How to check¶
No new PackageReference or PackageVersion line for Moq or another mocking library, and no new using Moq; in test files.
CS-DEP-006: Check what a security pin removes from the dependency graph¶
Severity: major · Applies to: service, library, template · Enforced by: manual · Status: active
Why¶
A pin that moves a package to a fixed version can change that package's own dependencies. When the new version drops a dependency, an assembly that another compiled package still binds is no longer restored. The build passes, the health endpoints answer, and a background service throws FileNotFoundException on every run, visible only in the logs.
Do¶
- Before and after a security pin or a major bump, compare the package lists in
project.assets.json, or the output ofdotnet list package --include-transitive. - For each package that disappears, check whether a package you did not change still needs it, and pin it explicitly when it does.
- After the change, start the host and read its log for
FileNotFoundExceptionandFileLoadException. - Follow ADR-0103 section 6 before you remove a security pin.
Don't¶
- Treat a green build and green health checks as proof that a pin is safe.
How to check¶
The change description lists the transitive packages that the pin added or removed.