ArchitectureGuardrails 0.1.0
dotnet add package ArchitectureGuardrails --version 0.1.0
NuGet\Install-Package ArchitectureGuardrails -Version 0.1.0
<PackageReference Include="ArchitectureGuardrails" Version="0.1.0" />
<PackageVersion Include="ArchitectureGuardrails" Version="0.1.0" />
<PackageReference Include="ArchitectureGuardrails" />
paket add ArchitectureGuardrails --version 0.1.0
#r "nuget: ArchitectureGuardrails, 0.1.0"
#:package ArchitectureGuardrails@0.1.0
#addin nuget:?package=ArchitectureGuardrails&version=0.1.0
#tool nuget:?package=ArchitectureGuardrails&version=0.1.0
ArchitectureGuardrails
Small, BCL-only helpers for writing explicit architecture tests in .NET: segment-aware namespace matching, signature dependency inspection, MSBuild project discovery and an inventory that shows which projects have architecture tests registered.
It is not a fluent rule engine, a test framework or an IL scanner. Your rules stay ordinary tests in your own test project, written with the test framework you already use. The package targets net10.0 (consumable from .NET 10 and .NET 11) and has zero runtime package dependencies.
Write a rule
using ArchitectureGuardrails;
using Xunit;
public sealed class DomainRules
{
[Fact]
[ArchitectureTestFor(typeof(OrderEntity))]
public void DomainSignaturesDoNotDependOnInfrastructure()
{
var domainTypes = typeof(OrderEntity).Assembly.GetTypes()
.Where(type => ReflectionMetadata.IsInNamespace(type.Namespace, "MyApp.Domain"))
.ToArray();
Assert.NotEmpty(domainTypes); // a namespace typo must not pass silently
var violations = domainTypes
.SelectMany(type => ReflectionMetadata.SignatureDependencies(type)
.Where(dependency => ReflectionMetadata.IsInNamespace(dependency.Namespace, "MyApp.Infrastructure"))
.Select(dependency => $"{type.FullName} -> {dependency.FullName}"))
.ToArray();
Assert.True(violations.Length == 0, string.Join(Environment.NewLine, violations));
}
}
ReflectionMetadata.IsInNamespacetreatsMyApp.DomainExtraas not insideMyApp.Domain.ReflectionMetadata.SignatureDependenciesreads base types, interfaces, fields, properties, events, constructor and method signatures and generic constraints. It does not read method bodies.[ArchitectureTestFor(typeof(T))]registers the test for the assembly that containsT.
Inventory: which projects have architecture tests?
using System.Reflection;
using ArchitectureGuardrails;
using Xunit;
public sealed class ArchitectureInventoryTests
{
[Fact]
public async Task EveryProjectHasArchitectureTests()
{
var testAssembly = typeof(ArchitectureInventoryTests).Assembly;
var root = ProjectDiscovery.FindRepositoryRoot(AppContext.BaseDirectory, "MyApp.slnx");
var projects = await ProjectDiscovery.DiscoverAsync(root,
ProjectDiscoveryOptions.ForAssembly(testAssembly), TestContext.Current.CancellationToken);
var report = ArchitectureInventory.CreateReport(projects, testAssembly.GetTypes(), IsXunitTest);
foreach (var entry in report.Uncovered)
{
TestContext.Current.AddWarning(entry.ToString()); // visible even when the test passes
}
var settings = InventorySettings.Load(Path.Combine(AppContext.BaseDirectory, "testsettings.json"));
ArchitectureInventory.Enforce(report, settings);
}
private static bool IsXunitTest(MethodInfo method) =>
method.GetCustomAttributes<FactAttribute>().Any(fact => fact.Skip is null && !fact.Explicit);
}
Copy testsettings.json to the test output (CopyToOutputDirectory=PreserveNewest). Uncovered projects are warnings by default; opt into failure with:
{ "EnforceCoverage": true }
ProjectDiscovery runs dotnet msbuild -getProperty for each non-test .csproj (it does not build), so build the solution before running tests. For multi-targeted projects, pass TargetFramework through ProjectDiscoveryOptions.Properties.
What a green result does not mean
- Method bodies, general attributes, reflection strings and dynamic loading are not analyzed.
- A GREEN inventory entry means a test is registered, not that it passed or that all necessary rules exist.
- Only load trusted assemblies and evaluate trusted repositories in the test process.
Full documentation, design notes and examples: https://github.com/jmfloreszazo/ArchitectureTests
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- 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.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 0 | 12/1/2026 |