AutoArchitecture 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package AutoArchitecture --version 1.0.0
                    
NuGet\Install-Package AutoArchitecture -Version 1.0.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="AutoArchitecture" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoArchitecture" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AutoArchitecture" />
                    
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 AutoArchitecture --version 1.0.0
                    
#r "nuget: AutoArchitecture, 1.0.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 AutoArchitecture@1.0.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=AutoArchitecture&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AutoArchitecture&version=1.0.0
                    
Install as a Cake Tool

AutoArchitecture

NuGet NuGet Downloads CI License: MIT

Free, MIT-licensed compile-time architecture rule enforcement for .NET. No commercial license, no separate desktop tool, no CI-only step — violations show up as build warnings/errors the moment they're introduced, right in your IDE.

Why AutoArchitecture?

Tools like NDepend are excellent for deep codebase analysis but require a paid commercial license. If all you need is "the UI layer must never reference the data-access layer directly," you shouldn't need a separate license and a separate analysis pass for that. AutoArchitecture is a Roslyn source generator: declare your rules once as assembly attributes, and every build enforces them for free.

[assembly: AutoArchitecture.ForbidDependency("MyApp.UI", "MyApp.DataAccess",
    Because = "UI must go through the service layer, not the repositories directly")]

The moment any type in MyApp.UI (or a sub-namespace like MyApp.UI.Views) references a type in MyApp.DataAccess (or a sub-namespace), you get:

warning AA001: 'OrderController' in namespace 'MyApp.UI' references 'OrderRepository' in
namespace 'MyApp.DataAccess', which is forbidden by
[assembly: ForbidDependency("MyApp.UI", "MyApp.DataAccess")]
(UI must go through the service layer, not the repositories directly)

Install

dotnet add package AutoArchitecture

Usage

Add one [assembly: ForbidDependency(from, to)] attribute per rule anywhere in your project (e.g. in AssemblyInfo.cs or alongside your Program.cs):

[assembly: AutoArchitecture.ForbidDependency("MyApp.Presentation", "MyApp.Infrastructure")]
[assembly: AutoArchitecture.ForbidDependency("MyApp.Domain", "MyApp.Infrastructure")]
  • Namespace matching includes sub-namespaces: a rule for MyApp.DataAccess also covers MyApp.DataAccess.Sql, MyApp.DataAccess.Migrations, etc.
  • Rules only match on exact/dot-boundary prefixes, so MyApp.DataAccess does not accidentally match an unrelated MyApp.DataAccessLegacy namespace.
  • The Because named argument is optional and is included verbatim in the diagnostic message — handy for explaining why the rule exists to whoever hits it next.
  • AA001 is a Warning by default. Promote it to a build-breaking error per-project with a standard .editorconfig severity override:
    dotnet_diagnostic.AA001.severity = error
    

Design goals

  • MIT licensed, forever. No commercial tier, no per-seat fees, no desktop app to buy.
  • Zero runtime cost — this is a source generator/analyzer; nothing ships in your compiled output.
  • IDE-first feedback — violations appear as squiggles while you type, not just in a nightly CI report.
  • Simple, declarative rules — no XML rule files or query languages to learn.

Roadmap

  • Allow-list exceptions for specific types within an otherwise-forbidden namespace pair are planned for a future release, to support gradual migrations.

💼 Need .NET consulting?

I'm the author of AutoArchitecture and a suite of compile-time source generators (AutoWire, AutoMap.Generator) and 28+ Polly v8 resilience packages. I'm available for consulting on Polly v8 resilience, Azure cloud architecture, and clean .NET design.

→ solidqualitysolutions.com · LinkedIn

Also by the same author

🌐 Full suite overview: swevo.github.io

Package Description
AutoAssert Free, MIT-licensed fluent assertions — alternative to FluentAssertions' commercial license.
EFCore.BulkOperations Free, MIT-licensed bulk insert/update/delete for EF Core.
AutoWire Compile-time DI auto-registration — [Scoped]/[Singleton]/[Transient] generates IServiceCollection registration code.
AutoMap.Generator Compile-time object mapping — [Map(typeof(Dto))] generates ToDto() extension methods.
AutoDispatch.Generator Compile-time CQRS dispatcher — free alternative to MediatR's commercial license.

License

MIT © Justin Bannister

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.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
1.1.0 107 7/10/2026
1.0.1 102 7/7/2026
1.0.0 108 7/7/2026

1.0.0: Initial release. [assembly: ForbidDependency(from, to)] with AA001 diagnostic.