.NET tasks AI is better at than developers
Creating projects, writing unit tests, adding comments and debugging exceptions. With the right prompts, AI is better than .NET developers at all of it. We are going to use Claude Code to do each of these tasks on an ASP.NET Core Web API, using markdown spec files to tell it exactly what we want.
Creating a .NET project with Claude Code
If you are still creating your .NET projects by hand, you are wasting your time. We added a markdown spec file called 01-create-project.md to an empty folder, and gave Claude Code this prompt:
/plan Read 01-create-project.md and plan how you are going to build it
Adding /plan to the start of the prompt puts Claude Code into plan mode. Rather than making changes straight away, it reads the spec file and comes up with a plan of how it is going to build the project. Once you are happy with the plan, you can get Claude Code to execute it.
What the spec file contains
The spec file gives Claude Code the general requirements for how we want the project built and structured. It includes:
The framework and language versions, which are .NET 10 and C# 14, with SQL Server for the database
A Clean Architecture solution with an Api, Application and Infrastructure project, along with the folder structure and project references
The setup order, including creating a
.slnxsolution file and setting up Central Package ManagementThe NuGet packages to install, with instructions to look up the latest stable version of each one
Coding rules, such as using file scoped namespaces and extension members, putting each type in a separate file, passing a
CancellationTokenthrough every async call and not adding any commentsAn endpoint that returns every product that has not been deleted, along with the database layout for the
ProductstableInstructions to build and run the project, check the Swagger documentation loads, and generate a CLAUDE.md file so future sessions follow the same rules
It also tells Claude Code not to generate any Entity Framework Core migrations. Instead, it provides instructions for adding them manually.
The spec file took a couple of hours to write, going back and forth with Claude to perfect it. But once it is written, it can be reused whenever you need to create another project.
The plan Claude Code created
Claude Code started by checking the environment, such as the .NET SDK version and whether SQL Server LocalDB was installed. The plan then included:
A description of what it was going to build
The steps needed to build it, following the setup order in the spec file
The files it was going to create in the Api, Application and Infrastructure projects
The files it was going to add to the root, including CLAUDE.md, a README.md with the migration instructions, and the Claude Code skills it would create for the project
Verification steps, such as building the solution, running the API to check the Swagger documentation loads, and confirming no comments had been added
The end result
Claude Code created the project in less than five minutes. The same task would take at least an hour by hand.
It created each of the projects and set up the integration with Entity Framework Core. Running the application loads the Swagger documentation, along with the endpoint we asked for in the spec file.
We think this is the direction the .NET developer role is heading over the next couple of years. A lot less coding, and more architectural decisions. If you are not using AI for tasks like this at the moment, you are going to fall behind other developers.
Get notified of new content
Join other .NET developers improving their skills and knowledge.
Writing unit tests with Claude Code
We can use the same approach to write unit tests. We created a similar spec file called 02-create-unit-tests.md, and gave Claude Code this prompt:
/plan Read 02-create-unit-tests.md and plan how you are going to build it
The spec file asks Claude Code to:
Create an ApiTests, ApplicationTests and InfrastructureTests project in a Tests folder, using xUnit v3
Use Moq for mocking, creating each mock in the test class constructor and setting up its behaviour inside each test
Store the result of the method being tested in a variable called
act, and passTestContext.Current.CancellationTokenwherever a method accepts aCancellationTokenTest the Minimal API endpoints by calling each handler directly
Test the repositories using the Entity Framework Core in memory provider, with a separate database for each test
Keep the test package versions in each test project's .csproj file, rather than in Central Package Management
Build the solution, run
dotnet testand confirm all the tests pass
The plan Claude Code came up with went through the context, listing the service, repository and endpoint methods that needed testing. It then went through the steps it needed to run, from creating the test projects and adding the packages, through to writing the tests and updating CLAUDE.md with the testing conventions. Finally, it added a verification section, before we took it out of plan mode and got it to create the unit tests.
The end result
Claude Code created the test projects in just over five minutes. It created a separate test project for each of the projects from the first step, and set up an in memory DbContext so the Entity Framework Core queries can be tested.
Running the tests shows they all pass. That is because the spec file told Claude Code to run dotnet test and confirm that all the tests pass.
Writing thorough unit tests by hand takes a long time. AI speeds this up, and it can also help you plan your unit tests, as it will find things you did not think to test. Some developers do not write unit tests at all, either because they find them too complicated or they simply cannot be bothered. With AI, there is no excuse.
Adding comments with Claude Code
The project we created does not have any comments in it, as the first spec file told Claude Code not to add them. We can use the same approach to add them now, using a spec file called 03-add-comments.md and this prompt:
/plan Read 03-add-comments.md and plan how you are going to build it
The spec file asks Claude Code to:
Add XML documentation comments to the Api, Application and Infrastructure projects, and only add
// Arrange,// Actand// Assertcomments to the test methodsTurn on
GenerateDocumentationFilein those three projects, so a missing comment gives aCS1591build warning, and fix every warning rather than suppressing itDocument every type, method, constructor, property, parameter and return type
Keep each comment to 60 characters or less, written in UK English, describing what the member does rather than repeating its name
Use
<inheritdoc />on interface implementations, with the full documentation on the interfaceReplace the rule about not adding comments in CLAUDE.md with the new documentation rules
The plan listed the comments it was going to add to each file, along with the changes to the test projects and CLAUDE.md. Its verification steps included building the solution to check there were no documentation warnings, and checking that no comment was over 60 characters.
Once executed, comments had been added to the classes, constructors, properties and methods. AI can add really long comments, but these are short because the spec file set a 60 character limit.
When developers do write comments, they often have spelling mistakes or grammatical errors. Parameter comments can also reference parameters that no longer exist, or have since been renamed. AI is good at spelling and grammar, and at keeping parameter comments up to date, so there is really no excuse not to comment your code.
Debugging an exception with Claude Code
AI is good at following architecture rules, but can it debug an issue quicker than a developer?
Running the endpoint returned a 500 error, and the exception was related to the database. We asked Claude Code to debug it with this prompt:
I ran the project. Went to run /api/products, but I get a SQL Server error. Can you debug it for me?
Claude Code found that there was no Migrations folder in the project. As a result, there was no database. The spec file had told Claude Code not to add the migrations so they could be added manually, but that step had been forgotten.
Claude Code took nearly four minutes to find the issue. That was because the API was still running in the background, so Claude Code was unable to run it itself to see the error. If you are asking Claude Code to debug an issue, stop the application first.
Fixing the issue
We created the migration and updated the database. This created the database, along with the Products table.
After adding a product to the table, running the endpoint again returned a successful response.
A SQL Server exception like this can easily send you down the wrong path. It is tempting to think the problem is the connection string or a network issue. All it was in this case was a migration that had not been run.
What this means for .NET developers
AI is frighteningly good at the .NET tasks featured in this article. Thankfully, in a recent LinkedIn poll that we did, only 6% of developers said they had lost their job because of AI.
That is likely to be because companies have been quite slow at adopting AI. But they will catch up, and if you do not learn these skills, you will fall behind and could find yourself looking for another job.
Watch the video
Watch the video where we use Claude Code to create a .NET project, write unit tests, add comments and debug a SQL Server exception.
And you can see the spec files, plans, prompts used in this article, along with the projects Claude Code created, by downloading the code example.
Related pages
Learn how to get Claude Code to follow your .NET code style by using a spec file, CLAUDE.md, and the right settings for permissions and migrations.
Adding a new .NET feature taking ages? We tested Claude Code on a real migration task to see how much time it could save.