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:
| Package | Previous version | New version |
|---|---|---|
Ardalis.CleanArchitecture.Template | 11.1.1 | 12.0.0 |
Ardalis.MinimalClean.Template | 1.1.1 | 12.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
| Area | v11.x | v12.x | Action |
|---|---|---|---|
| .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 versions | Required |
| Aspire | 13.0 | 13.6.5, Aspire.Hosting.AppHost package no longer referenced | Required |
| Strongly typed ID generation | In app code (VogenIdValueGenerator) | By the database (ValueGeneratedOnAdd, IDENTITY) | Recommended |
| Seed data | Static Contributor instances | Seed names plus SQL inserts | If you use SeedData in tests |
| Email (MailKit 5) | SendAsync(message) | SendAsync(new SendRequest(message)) | Update |
| Tests | xUnit v2, mixed Assert.* and Shouldly | xUnit v3, mostly Shouldly, SQL Server 2025 Testcontainer, working SQLite fallback | Required for xUnit v3 |
| Get-by-ID use case | Contributors/Get, GetContributorQuery | Contributors/GetById, GetContributorByIdQuery | Optional |
| Template generation | Hyphens and similar characters produced invalid namespaces | They’re converted to _ | None |
Before you start
- Install the .NET 11 SDK.
- Commit or back up your work, and back up any databases you’ll migrate.
- 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:
| Package | v11.1.1 | v12 |
|---|---|---|
| FastEndpoints, FastEndpoints.Swagger | 7.1.1 | 9.0.0 |
| FastEndpoints.ApiExplorer | 2.2.0 | 2.3.0 |
| MailKit | 4.15.1 | 5.0.0 |
| Serilog.AspNetCore | 9.0.0 | 10.0.0 |
| Swashbuckle.AspNetCore (+ Annotations) | 6.5.0 | 11.0.0 |
| NSubstitute | 5.3.0 | 6.2.0 |
| coverlet.collector | 6.0.4 | 10.1.0 |
| xunit → xunit.v3.mtp-off | 2.9.3 | 4.0.3 |
| xunit.runner.visualstudio | 3.1.5 | 4.0.1 |
| Microsoft.NET.Test.Sdk | 18.0.1 | 18.12.0 |
| Aspire.Hosting.SqlServer, Aspire.Hosting.Testing | 13.0.0 / 9.5.1 | 13.6.5 |
| OpenTelemetry.* | 1.13.0 to 1.14.0 | 1.21.0 |
| Testcontainers, Testcontainers.MsSql | 4.3.0 | 4.16.0 |
| Scalar.AspNetCore | 2.10.3 | 2.20.0 |
| Azure.Identity | 1.17.0 | 1.21.0 |
| Vogen | 8.0.2 | 8.0.7 |
| ReportGenerator | 5.5.0 | 5.6.0 |
| SQLite | 3.13.0 | 3.54.1 |
New entries in Directory.Packages.props:
MessagePack3.1.12: referenced by the Aspire host to pick up a security fixSystem.Security.Cryptography.Pkcs11.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.Abstractionsreference (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’sAddValidatorsFromAssembly...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 theFluentValidation.DependencyInjectionExtensionspackage 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.Sdkprovides the app host, so the separateAspire.Hosting.AppHostpackage reference was removed (along with itsPackageVersion). - 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 anddotnet runkeep working without the Aspire CLI. With warnings treated as errors, you need theNoWarnfor 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:
- Rename
ContributorstoContributors_old, and its primary key to match. Passsp_renameunbracketed 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. - Create a new
Contributorstable withId int IDENTITY(1,1). - Copy the rows across with
SET IDENTITY_INSERT ON, keeping the existing IDs. - 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.
- For each entity that uses
VogenIdValueGenerator, replace.HasValueGenerator<...>()with.ValueGeneratedOnAdd(), then deleteVogenIdValueGenerator.cs. If the entity’s ID type has aValidatemethod that rejects zero or negative values, adddeserializationStrictness: DeserializationStrictness.AllowAnythingto its[ValueObject<int>]attribute. - Add a migration (
dotnet ef migrations add UseDbGeneratedIds ...; see Data & Migrations). EF Core’s generated migration can’t addIDENTITYto an existing SQL Server column, so replace itsUpandDownwith the rename-create-copy-drop pattern from the template’s20260424000000_UseDbGeneratedIds.cs, once per table, including any foreign keys that reference those tables. - 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:
IAsyncLifetimereturnsValueTask, notTask. For example, inCustomWebApplicationFactory:- 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
CancellationTokenwithout passing one, and with warnings as errors that fails the build. UseTestContext.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 newSqlServerOnLinuxTestscovers 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
ArgumentExceptionwhen the container failed to start, but newer Testcontainers versions report a missing Docker daemon withDockerUnavailableException, so the tests failed instead of falling back. v12 catchesDockerUnavailableException, also treats Docker running Windows containers as unavailable (a newDockerEnvironmenthelper checks), and uses a temporary SQLite database file that’s deleted afterward.
New test classes in the FunctionalTests project:
| Class | Purpose |
|---|---|
SqlServerOnLinuxTests | Runs 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. |
SqliteFallbackTests | Simulates Docker being unavailable and checks that the factory falls back to SQLite, and that it doesn’t when SQL Server is explicitly requested. |
DockerEnvironment, TestDatabaseProvider | Helpers 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
Getuse case renamed toGetById. In UseCases, theContributors/Getfolder and namespace becameContributors/GetById, andGetContributorQuery/GetContributorHandlerbecameGetContributorByIdQuery/GetContributorByIdHandler, matching the existingGetByIdendpoint. 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_namespacetransform when renaming files and namespaces, sodotnet new clean-arch -o My-Appproduces validMy_App.*namespaces and project names instead of broken ones. This only affects newly generated solutions. - Removed a stray
Clean.Architecture.Core.slnfile from the Core project folder. If your solution still hassrc/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), plusCONTRIBUTING.md,CODE_OF_CONDUCT.md,icon.png,.claude/,PARALLEL_TEST_EXECUTION.md, andTESTCONTAINERS_IMPLEMENTATION.mdfrom 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-archsolutions get a.gitignore. Earlier packages left it out, sogit initon a new solution picked upbin/,obj/, and the SQLite database. If your solution doesn’t have one, copy it from a newly generated solution, or rundotnet new gitignore. - Installing
Ardalis.CleanArchitecture.Templateno longer installsmin-cleantoo. The v11 package accidentally included the Minimal Clean template. To use it, installArdalis.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.jsonSDK11.0.100,TargetFrameworknet11.0CentralPackageTransitivePinningEnabledadded toDirectory.Build.propsPackages 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.Sdk13.6.5 and theASPIRE010NoWarn, as in step 3. The minimal app host still referencesAspire.Hosting.AppHost, now at 13.6.5.MailKit 5: the same
SendRequestchange as step 6nuget.configadded, using nuget.org with package source mappingMore NsDepCop rules in
config.nsdepcop:Domainmay no longer depend onCartFeatures,ProductFeatures, orConfigurations, and the two feature slices may no longer depend on each other.LoggingBehaviormoved out of a strayNimble.Modulith.Webnamespace 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.Productconstructor fix. The publicProduct(ProductId id, string name, decimal unitPrice)constructor’s guard was inverted: it rejected real IDs and acceptedProductId.New. It now rejectsProductId.New, andProduct.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.
