AI-Powered Applications with .NET Fundamentals: Building Intelligent Applications with .NET 11

AI-Powered Applications with .NET Fundamentals: Building Intelligent Applications with .NET 11

13+

Build Contoso Support Copilot with .NET 11: prompts, streaming, retrieval with citations, agents, evaluation, and operations.

0 followers
23 chapters
Software & AI Development
2026
You're viewing a limited preview. Create a free account to read free books or get Premium to unlock the entire library.

About This Book

AI-Powered Applications with .NET Fundamentals teaches you to build a real AI feature into a .NET application and keep it working. You will build Contoso Support Copilot, a support assistant that summarizes tickets, drafts replies, answers from a knowledge base with citations and coordinates small agents. Each chapter adds one capability to the same solution, so you see how prompts, retrieval, agents and operations fit together in code you can run.

Who This Book Is For

You can already write C# classes, interfaces and async methods, and you have used dependency injection in an ASP.NET Core application. You do not need machine learning experience. The book explains how language models, embeddings and agents behave from the application side: what goes in, what comes back and what can go wrong. The running project also uses Entity Framework Core basics (a DbContext, queries and SaveChanges), async streams and System.Text.Json; the activities' tests use xUnit and Moq, which Chapter 6 shows in full, and Chapter 12 assumes basic Docker and Kubernetes knowledge.

What You Will Build

Part I connects the application to a model through Microsoft.Extensions.AI, so one IChatClient abstraction works with every provider, and covers prompts, streaming, token usage and cost. Part II adds Semantic Kernel where it still fits, structured output that is validated before use, and testable services with conversation state. Part III indexes a support knowledge base with embeddings and vector search, builds retrieval-augmented generation with grounding and safety boundaries, and measures answer quality. Part IV builds agents with Microsoft Agent Framework and coordinates them in a resumable multi-agent workflow. Part V adds telemetry, tests, performance work and a container deployment.

Download the companion code free at unqbd.com/go/ai2-code. Each ChapterNN folder is the complete solution at the end of that chapter, so you can start any chapter from the previous checkpoint. If you build the project yourself instead, copy from each chapter's folder the files its Full Example lists but its steps do not show, such as ChapterCheck.cs and the sample data. When a listing says (excerpt), copy the complete file from that chapter's companion folder. Activity solutions are in ChapterNN/Activity, and every chapter from Chapter 6 on includes a test project. Activities are side exercises: start the next chapter from your main-path solution or from the previous ChapterNN folder. Chapter 11 is the one exception and starts from Chapter10/Activity.

Release Baseline

The examples target net11.0 and use the .NET 11 SDK, version 11.0.100 or later. Microsoft.Extensions.AI, Microsoft Agent Framework, Semantic Kernel and the OpenAI SDK have their own version numbers. The companion code pins the versions that were current at the time of writing; read each library's release notes before you upgrade, because these libraries change quickly.

Models change even faster. The book names models only as examples at the time of writing and reads every deployment name from configuration. Some current models reject sampling settings such as temperature; the code shows how to handle that. Under Microsoft's support policy, odd-numbered .NET releases such as .NET 11 receive Standard Term Support for two years. Check the current Microsoft .NET support policy when you choose a production baseline.

You Do Not Need an AI Account to Start

Every chapter runs in an offline mode by default. A deterministic local client stands in for the model and labels its output, so you can run the code, the tests and the checks without an account, a key or a network connection after the package restore. Offline output shows how the application works, not how well a model answers.

For real answers, switch the configuration to a free local model with Ollama, to a Microsoft Foundry (formerly Azure AI Foundry) deployment or to OpenAI. A small local model such as llama3.2 runs the checks of Chapters 2 to 7. From Chapter 8 on, the code requires citations in an exact format, scores from a judging model, and agents that call tools correctly. At the time of writing, small local models such as llama3.2 and qwen2.5:7b do not meet all three reliably, so use a Foundry or OpenAI deployment for Chapters 8 to 12. The agent chapters (Chapters 10 to 12) need a chat model that supports tool calling, which lets the model ask your code to run a method; offline mode runs every chapter too. Cloud models bill per token; the cost figures in the book are examples at the time of writing, so check current pricing before you run large evaluations.

Local Prerequisites

On Windows, install Visual Studio 2026 with the ASP.NET and web development workload and the .NET 11 SDK, version 11.0.100 or later. Visual Studio is the main path for creating the solution, managing packages, debugging, running tests and inspecting API requests. VS Code with C# Dev Kit is the alternative on Windows, macOS or Linux; its terminal commands use the same projects and package versions. The default database is SQLite, so no database server is needed; SQL Server, including LocalDB, is optional. Docker is optional for the Chapter 12 container image. An Azure subscription is needed only if you choose Microsoft Foundry, Azure AI Search or the Chapter 12 deployment to Azure Kubernetes Service, and the Azure CLI only for keyless access to Foundry or Azure AI Search and for that deployment.

An indented continuation in a printed code listing belongs to the line above. Keep any printed hyphen when you type the whole line.

Run a Checkpoint

Start with the companion's first complete checkpoint so you can see a working result before reading its layers. Chapter 2 then shows how to create the solution yourself. On Windows, copy the AI edition folder to a short local path, such as C:\Code\AiBook, keeping global.json beside the ChapterNN folders. Long paths can make Visual Studio's generated files fail to build. If that happens, move this edition folder to the shorter path and reopen the solution.

1. In Visual Studio, choose File > Open > Project/Solution and open Chapter01/ContosoSupportCopilot.slnx from the extracted companion. Open one chapter solution at a time; each checkpoint intentionally repeats the same project names.
2. In Solution Explorer, right-click ContosoSupportCopilot.Api and choose Set as Startup Project. The Domain and Infrastructure projects are libraries, so neither starts a server by itself.
3. Select Offline check beside the green Start button and press Ctrl+F5. This profile sets the AI provider to Offline, uses local SQLite and the in-memory vector store, and disables model judges and telemetry export for this run. It overrides provider settings saved in user secrets, so it is the learning route even after you have configured a real provider.
4. Read the provider line and the final Check passed. line. The console then exits. A successful offline check proves the application's path works with its stand-in; it does not judge a model's answers, costs or latency.
5. Choose http and press F5 to serve the API under the debugger. This profile uses your configured provider. On a fresh download it is Offline, but settings stored in Chapter 2's user-secrets store apply to later chapters too. Stop the session with Shift+F5. Chapter 1 maps no endpoints and returns 404; Chapter 2 adds the health URLs.
6. From Chapter 6 on, build with Ctrl+Shift+B, open Test > Test Explorer and run the tests. To debug one test, right-click that test and choose Debug rather than starting the API project.

Provider check runs --check using your configured provider. Select it only when you deliberately want real model calls; cloud calls are billed, and later checks make many of them. Profiles are local launch settings and do not configure a deployed server.

In VS Code, open the ChapterNN folder, let C# Dev Kit load its solution and use its terminal. The explicit offline command is dotnet run --project ContosoSupportCopilot.Api --launch-profile "Offline check"; dotnet run --project ContosoSupportCopilot.Api -- --check uses the normal profile and its configured provider. Omit -- --check to serve the API. Run dotnet test from the chapter folder when it has a test project. The companion README lists the settings, endpoints and what each check exercises.

Enjoying this book?

Create a free account to leave comments, track your progress, and more!

Read and listen on the go with the unQbd app. Get the app
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.