Upgrading from template v11.x to v12.x

These are template versions, not .NET versions. Template v11.x targets .NET 10. Template v12.x targets .NET 11. See Versions.

This guide is for solutions generated from Ardalis.CleanArchitecture.Template 11.x (for example 11.1.1), or from Ardalis.MinimalClean.Template 1.x, that want to adopt the changes in 12.x. A section at the end covers the Minimal Clean template.

Compared with v10 to v11, this is a smaller upgrade: a new .NET version, package updates (several of them major versions), a fix to how strongly typed IDs are generated, and the move to xUnit v3. The API endpoints and domain model are otherwise unchanged, and the only use case change is a rename.

Version numbers

Starting with 12.0.0, both templates share one version number and ship together:

PackagePrevious versionNew version
Ardalis.CleanArchitecture.Template11.1.112.0.0
Ardalis.MinimalClean.Template1.1.112.0.0

MinimalClean jumps from 1.1.1 to 12.0.0 only to align the version numbers. It didn’t change any more than the full template did.

Summary

Areav11.xv12.xAction
.NET.NET 10 (net10.0, SDK 10.0.100).NET 11 (net11.0, SDK 11.0.100)Required
NuGet packages.NET 10-era versions.NET 11 and latest versionsRequired
Aspire13.013.6.5, Aspire.Hosting.AppHost package no longer referencedRequired
Strongly typed ID generationIn app code (VogenIdValueGenerator)By the database (ValueGeneratedOnAdd, IDENTITY)Recommended
Seed dataStatic Contributor instancesSeed names plus SQL insertsIf you use SeedData in tests
Email (MailKit 5)SendAsync(message)SendAsync(new SendRequest(message))Update
TestsxUnit v2, mixed Assert.* and ShouldlyxUnit v3, mostly Shouldly, SQL Server 2025 Testcontainer, working SQLite fallbackRequired for xUnit v3
Get-by-ID use caseContributors/Get, GetContributorQueryContributors/GetById, GetContributorByIdQueryOptional
Template generationHyphens and similar characters produced invalid namespacesThey’re converted to _None

Before you start

  1. Install the .NET 11 SDK.
  2. Commit or back up your work, and back up any databases you’ll migrate.
  3. Generate a v11.1.1 solution and a v12 solution with your project name, and diff them. See the diff strategy. Everything below describes what that diff shows and why.

1. Move to .NET 11

In global.json:

 {
   "sdk": {
-    "version": "10.0.100",
+    "version": "11.0.100",
     "rollForward": "latestMajor",
     "allowPrerelease": true
   }
 }

In Directory.Build.props:

-    <TargetFramework>net10.0</TargetFramework>
+    <TargetFramework>net11.0</TargetFramework>

Check for projects that set their own TargetFramework. In v11 the AspireTests project hard-coded net9.0; it now uses net11.0.

If your CI workflows install the SDK explicitly, update them too (for example dotnet-version: '11.0.x' in actions/setup-dotnet).

2. Update packages

All versions live in Directory.Packages.props (a few entries there, such as Swashbuckle and FastEndpoints.ApiExplorer, aren’t referenced by any template project). Update the Microsoft.* packages (EF Core, Microsoft.Extensions.*, Microsoft.AspNetCore.Mvc.Testing) from 10.0.0 to 11.0.0, then the rest. Notable changes, with major version bumps in bold:

Packagev11.1.1v12
FastEndpoints, FastEndpoints.Swagger7.1.19.0.0
FastEndpoints.ApiExplorer2.2.02.3.0
MailKit4.15.15.0.0
Serilog.AspNetCore9.0.010.0.0
Swashbuckle.AspNetCore (+ Annotations)6.5.011.0.0
NSubstitute5.3.06.2.0
coverlet.collector6.0.410.1.0
xunit → xunit.v3.mtp-off2.9.34.0.3
xunit.runner.visualstudio3.1.54.0.1
Microsoft.NET.Test.Sdk18.0.118.12.0
Aspire.Hosting.SqlServer, Aspire.Hosting.Testing13.0.0 / 9.5.113.6.5
OpenTelemetry.*1.13.0 to 1.14.01.21.0
Testcontainers, Testcontainers.MsSql4.3.04.16.0
Scalar.AspNetCore2.10.32.20.0
Azure.Identity1.17.01.21.0
Vogen8.0.28.0.7
ReportGenerator5.5.05.6.0
SQLite3.13.03.54.1

New entries in Directory.Packages.props:

  • MessagePack 3.1.12: referenced by the Aspire host to pick up a security fix
  • System.Security.Cryptography.Pkcs 11.0.0: pins a transitive dependency (central transitive pinning is enabled)

Removed:

  • Aspire.Hosting.AppHost (see the next step)
  • The Core project’s Microsoft.Extensions.Logging.Abstractions reference (it wasn’t needed)

The template’s own code needed no changes for FastEndpoints 8 and 9, Serilog 10, or Swashbuckle 11. If you’ve written code against APIs that changed in those major versions, check their release notes. Because the solution treats warnings as errors, newly obsolete APIs show up as build errors.

FastEndpoints 9 resolves endpoint validators as singletons from the root service provider. If you also register your Validator<T> classes with FluentValidation’s AddValidatorsFromAssembly... methods (as scoped services), requests fail in Development with Cannot resolve scoped service … from root provider. FastEndpoints discovers its validators itself, so remove that registration (and the FluentValidation.DependencyInjectionExtensions package if nothing else uses it). The template never had it; the repository’s sample app did.

3. Update the Aspire app host

In src/Your.ProjectName.AspireHost/Your.ProjectName.AspireHost.csproj:

-<Project Sdk="Aspire.AppHost.Sdk/13.0.0">
+<Project Sdk="Aspire.AppHost.Sdk/13.6.5">

   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <IsAspireHost>true</IsAspireHost>
     <UserSecretsId>...</UserSecretsId>
+    <!-- ASPIRE010: we intentionally use the DCP/Dashboard NuGet packages (AspireUseCliBundle=false) so F5 and dotnet run work without the Aspire CLI -->
+    <NoWarn>$(NoWarn);ASPIRE010</NoWarn>
   </PropertyGroup>

   <ItemGroup>
-    <PackageReference Include="Aspire.Hosting.AppHost" />
     <PackageReference Include="Aspire.Hosting.SqlServer" />
+    <PackageReference Include="MessagePack" />
   </ItemGroup>
  • The Aspire.AppHost.Sdk provides the app host, so the separate Aspire.Hosting.AppHost package reference was removed (along with its PackageVersion).
  • Newer Aspire versions warn (ASPIRE010) when the app host uses the DCP and dashboard NuGet packages instead of the Aspire CLI bundle. The template does that on purpose, so F5 and dotnet run keep working without the Aspire CLI. With warnings treated as errors, you need the NoWarn for the build to succeed.

The solution folder also gains an aspire.config.json that points the Aspire CLI at the app host, so aspire run works:

{
  "appHost": {
    "path": "src/Your.ProjectName.AspireHost/Your.ProjectName.AspireHost.csproj"
  }
}

4. Strongly typed IDs are now generated by the database

What changed. In v11, Contributor IDs were assigned by a custom EF Core value generator, VogenIdValueGenerator, which computed the highest existing ID + 1 in application code. That isn’t safe when two requests insert at the same time (both can pick the same ID), and it has to query the table on every insert. In v12 the database generates the ID:

 builder.Property(entity => entity.Id)
-  .HasValueGenerator<VogenIdValueGenerator<AppDbContext, Contributor, ContributorId>>()
+  .ValueGeneratedOnAdd()
   .HasVogenConversion()
   .IsRequired();

Data/Config/VogenIdValueGenerator.cs was deleted.

The schema change. On SQL Server, the Id column now needs to be an IDENTITY column. SQL Server can’t add IDENTITY to an existing column with ALTER COLUMN, so the template’s new migration, UseDbGeneratedIds, does it in steps on SQL Server only:

  1. Rename Contributors to Contributors_old, and its primary key to match. Pass sp_rename unbracketed names (EXEC sp_rename N'Contributors', N'Contributors_old'): brackets in the new name become part of the name, and the later steps then can’t find the table.
  2. Create a new Contributors table with Id int IDENTITY(1,1).
  3. Copy the rows across with SET IDENTITY_INSERT ON, keeping the existing IDs.
  4. Drop Contributors_old.

SQLite needs no change, because its integer primary keys already auto-increment.

The ID type change. With database-generated keys, EF Core gives each new entity a temporary negative key until SaveChanges, and converts it to your strongly typed ID. ContributorId validates that IDs are positive, so that conversion would make every insert fail. v12 tells Vogen to skip validation when deserializing (which is how EF Core’s value converter creates IDs), while ContributorId.From() in your own code still validates:

-[ValueObject<int>]
+[ValueObject<int>(deserializationStrictness: DeserializationStrictness.AllowAnything)]
 public readonly partial struct ContributorId

What to do.

  1. For each entity that uses VogenIdValueGenerator, replace .HasValueGenerator<...>() with .ValueGeneratedOnAdd(), then delete VogenIdValueGenerator.cs. If the entity’s ID type has a Validate method that rejects zero or negative values, add deserializationStrictness: DeserializationStrictness.AllowAnything to its [ValueObject<int>] attribute.
  2. Add a migration (dotnet ef migrations add UseDbGeneratedIds ...; see Data & Migrations). EF Core’s generated migration can’t add IDENTITY to an existing SQL Server column, so replace its Up and Down with the rename-create-copy-drop pattern from the template’s 20260424000000_UseDbGeneratedIds.cs, once per table, including any foreign keys that reference those tables.
  3. Run it against a copy of production data first.

If your app has only SQLite databases, or you haven’t deployed yet, you can skip the custom migration and recreate the database instead.

5. Seed data

SeedData no longer holds Contributor entity instances. It holds the seed names, and inserts rows with SQL (which avoids key generation and value conversion issues with value-object IDs):

-public static readonly Contributor Contributor1 = new(ContributorName.From("Ardalis"));
-public static readonly Contributor Contributor2 = new(ContributorName.From("Ilyana"));
+public static readonly ContributorName Contributor1Name = ContributorName.From("Ardalis");
+public static readonly ContributorName Contributor2Name = ContributorName.From("Ilyana");

PopulateTestDataAsync now uses dbContext.Database.ExecuteSqlAsync(...) inserts instead of AddRange and SaveChangesAsync. Update tests that referenced SeedData.Contributor1.Name to use SeedData.Contributor1Name. If you’ve replaced the seed data with your own, you can keep your approach.

6. MailKit 5

With MailKit 5, the template sends through the SendAsync overload that takes a SendRequest. In Infrastructure/Email/MimeKitEmailSender.cs:

-    await client.SendAsync(message);
+    await client.SendAsync(new MailKit.SendRequest(message));

7. Tests

xUnit v2 to xUnit v3

Every test project switched from the xunit package to xunit.v3.mtp-off (xUnit v3, running on VSTest so dotnet test and IDE test explorers behave as before):

-    <PackageReference Include="xunit" />
+    <PackageReference Include="xunit.v3.mtp-off" />

Code changes this requires:

  • IAsyncLifetime returns ValueTask, not Task. For example, in CustomWebApplicationFactory:

    -  public async Task InitializeAsync()
    +  public async ValueTask InitializeAsync()
    ...
    -  public new async Task DisposeAsync()
    +  public new async ValueTask DisposeAsync()
    
  • Pass the test cancellation token. xUnit v3’s analyzer warns when a test calls an async method that accepts a CancellationToken without passing one, and with warnings as errors that fails the build. Use TestContext.Current.CancellationToken:

    var cancellationToken = TestContext.Current.CancellationToken;
    await repository.AddAsync(contributor, cancellationToken);

See the xUnit v3 migration guide for anything else your tests use.

More Shouldly

Most Assert.Equal and Assert.Contains calls were replaced with Shouldly, which the template already referenced (two Assert.Throws calls remain, and Assert.Skip skips the tests that need Docker):

-Assert.Equal(SeedData.NUMBER_OF_CONTRIBUTORS, result.TotalCount);
+result.TotalCount.ShouldBe(SeedData.NUMBER_OF_CONTRIBUTORS);

This is a convention, not a requirement. Your existing assertions keep working.

Functional test fixture

In CustomWebApplicationFactory:

  • The SQL Server image moved from 2022 to 2025, and the image is passed to the builder’s constructor (newer Testcontainers versions expect this):

    -_dbContainer = new MsSqlBuilder()
    -  .WithImage("mcr.microsoft.com/mssql/server:2022-latest")
    +_dbContainer = new MsSqlBuilder("mcr.microsoft.com/mssql/server:2025-latest")
       .WithPassword("Your_password123!")
       .Build();
    
  • The schema is always created with EnsureCreated(), for both SQL Server and the SQLite fallback, rather than running migrations for SQL Server. This keeps functional tests independent of migration scripts. (Migrations still run at app startup, and the new SqlServerOnLinuxTests covers them.)

  • Seeding uses .GetAwaiter().GetResult() instead of .Wait(), and seeding errors are logged and rethrown, so a broken seed fails the tests instead of producing confusing failures later.

  • The SQLite fallback works. In v11 the factory caught only ArgumentException when the container failed to start, but newer Testcontainers versions report a missing Docker daemon with DockerUnavailableException, so the tests failed instead of falling back. v12 catches DockerUnavailableException, also treats Docker running Windows containers as unavailable (a new DockerEnvironment helper checks), and uses a temporary SQLite database file that’s deleted afterward.

New test classes in the FunctionalTests project:

ClassPurpose
SqlServerOnLinuxTestsRuns the real migrations against an empty SQL Server container and checks that existing rows survive UseDbGeneratedIds. Skipped without Docker unless REQUIRE_SQL_SERVER_TESTS=true.
SqliteFallbackTestsSimulates Docker being unavailable and checks that the factory falls back to SQLite, and that it doesn’t when SQL Server is explicitly requested.
DockerEnvironment, TestDatabaseProviderHelpers for the above: the Docker check, and an Auto / SqlServer / Sqlite provider choice.

DockerAvailabilityTests now uses DockerEnvironment and, without Docker, is skipped with an explanatory message (Assert.Skip) instead of failing. See Building & Testing.

Integration tests

A new test, AddsTwoContributorsWithDistinctDbGeneratedIds, checks that two inserted contributors get distinct generated IDs. A new SqliteContributorPersistence test class runs against in-memory SQLite (a relational provider, unlike EF Core’s in-memory provider), so it catches the temporary-key validation problem described in step 4. The IntegrationTests project also gained a Testcontainers.MsSql reference.

8. Other changes

  • Get use case renamed to GetById. In UseCases, the Contributors/Get folder and namespace became Contributors/GetById, and GetContributorQuery / GetContributorHandler became GetContributorByIdQuery / GetContributorByIdHandler, matching the existing GetById endpoint. The unit test class was renamed to match. Behavior is unchanged, so this rename is optional for existing solutions.
  • Template naming fix. The templates now use a safe_namespace transform when renaming files and namespaces, so dotnet new clean-arch -o My-App produces valid My_App.* namespaces and project names instead of broken ones. This only affects newly generated solutions.
  • Removed a stray Clean.Architecture.Core.sln file from the Core project folder. If your solution still has src/Your.ProjectName.Core/Your.ProjectName.Core.sln, you can delete it.
  • Generated solutions no longer include repository-only files. Solutions generated from v11 also contained a MinimalClean/ folder (a full copy of the other template), plus CONTRIBUTING.md, CODE_OF_CONDUCT.md, icon.png, .claude/, PARALLEL_TEST_EXECUTION.md, and TESTCONTAINERS_IMPLEMENTATION.md from the template repository. None of them are part of your application, so you can delete them. The useful parts of the two testing notes, updated for v12, are on the Building & Testing page.
  • New clean-arch solutions get a .gitignore. Earlier packages left it out, so git init on a new solution picked up bin/, obj/, and the SQLite database. If your solution doesn’t have one, copy it from a newly generated solution, or run dotnet new gitignore.
  • Installing Ardalis.CleanArchitecture.Template no longer installs min-clean too. The v11 package accidentally included the Minimal Clean template. To use it, install Ardalis.MinimalClean.Template (see Getting Started).
  • Documentation moved from the README to this site, cleanarchitecture.ardalis.com.

Changes in the sample application only

The repository’s sample app (not part of either template) tightened its value object validation, following discussion #1053. Names and titles now reject whitespace-only strings (string.IsNullOrWhiteSpace), and to-do item descriptions may be empty but not null. The template’s ContributorName still uses string.IsNullOrEmpty. Consider which rule fits each of your own value objects.

Minimal Clean template

Ardalis.MinimalClean.Template moves from 1.1.1 to 12.0.0 (see Version numbers) and gets the matching changes:

  • .NET 11: global.json SDK 11.0.100, TargetFramework net11.0

  • CentralPackageTransitivePinningEnabled added to Directory.Build.props

  • Packages updated as above, plus NsDepCop 2.6.0 → 3.3.0 and MimeKit 4.15.1 → 5.0.0. Unused package versions were removed from Directory.Packages.props.

  • Aspire app host: Aspire.AppHost.Sdk 13.6.5 and the ASPIRE010 NoWarn, as in step 3. The minimal app host still references Aspire.Hosting.AppHost, now at 13.6.5.

  • MailKit 5: the same SendRequest change as step 6

  • nuget.config added, using nuget.org with package source mapping

  • More NsDepCop rules in config.nsdepcop: Domain may no longer depend on CartFeatures, ProductFeatures, or Configurations, and the two feature slices may no longer depend on each other. LoggingBehavior moved out of a stray Nimble.Modulith.Web namespace so the rules cover it. A violation fails the build, so if you adopt the rules, expect build errors wherever your slices reference each other directly. See Enforcing Dependency Rules for the rule syntax and how to add rules for new slices.

  • icon.png (the package icon) is no longer copied into new solutions. You can delete it from existing ones.

  • Product constructor fix. The public Product(ProductId id, string name, decimal unitPrice) constructor’s guard was inverted: it rejected real IDs and accepted ProductId.New. It now rejects ProductId.New, and Product.Create(name, unitPrice) uses a new private constructor for unsaved products:

    +  private Product(string name, decimal unitPrice)
    +  {
    +    Name = name;
    +    UnitPrice = unitPrice;
    +  }
    +
       public Product(ProductId id, string name, decimal unitPrice)
       {
    -    Guard.Against.InvalidInput(id, nameof(id), (id) => id == ProductId.New,
    +    Guard.Against.InvalidInput(id, nameof(id), (id) => id != ProductId.New,
           "Use Product.Create() to create new products instead of passing ProductId.New to the constructor.");
    ...
    -  public static Product Create(string name, decimal unitPrice) => new Product(ProductId.New, name, unitPrice);
    +  public static Product Create(string name, decimal unitPrice) => new Product(name, unitPrice);
    

    Apply the same fix to any aggregates you modeled on Product.