ArchitectureGuardrails 0.1.0

dotnet add package ArchitectureGuardrails --version 0.1.0
                    
NuGet\Install-Package ArchitectureGuardrails -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArchitectureGuardrails" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ArchitectureGuardrails" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ArchitectureGuardrails" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ArchitectureGuardrails --version 0.1.0
                    
#r "nuget: ArchitectureGuardrails, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ArchitectureGuardrails@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ArchitectureGuardrails&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ArchitectureGuardrails&version=0.1.0
                    
Install as a Cake Tool

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.IsInNamespace treats MyApp.DomainExtra as not inside MyApp.Domain.
  • ReflectionMetadata.SignatureDependencies reads 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 contains T.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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