PostSharp 2027.0 gives the agent the facts: the real API, what the build actually did, and tests to check the result. Here is what we added:
- PostSharp AI Plugin for Claude Code and Codex
- CLI Commands to Introspect Aspects Without Visual Studio
- Documentation of Every Build Message
- Aspect Test Framework
PostSharp AI Plugin for Claude Code and Codex
The PostSharp plugin for Claude Code and OpenAI Codex gives the agent the documentation it needs to work with PostSharp. The plugin contains all the articles in Markdown format, the API reference of every namespace, two scripts that find an article or an API, and compilable source code of all examples. It also instructs the agent to look up the API before writing code, to build to verify, and to fix the cause of a build message instead of silencing it.
In Claude Code:
/plugin marketplace add https://github.com/postsharp/PostSharp.AI.Skills
/plugin install postsharp
Available now from the PostSharp.AI.Skills marketplace. See Configuring AI Coding Agents, which also covers Codex.
CLI Commands to Introspect Aspects Without Visual Studio
The postsharp introspect commands tell, from the files of the last build, which aspects apply to a declaration, what created them, and what they changed, in which order.
postsharp introspect show declaration Orders/Repository.cs:10
The output, abridged:
{
"declaration": {
"id": "M:App.Orders.Repository.Save(App.Customer)",
"kind": "Method",
"location": "Orders/Repository.cs:10:21",
"project": "App",
"targetFrameworks": [ "net10.0" ]
},
"aspectInstances": {
"count": 1,
"truncated": false,
"items": [
{
"id": "f50384e0ebfe",
"aspectClass": { "name": "Lib.LogAttribute", "shortName": "Log" },
"predecessors": {
"count": 1,
"truncated": false,
"items": [
{
"id": "0374f134812d",
"kind": "Multicast",
"isKindInferred": true,
"declaration": { "id": "A:App", "kind": "Assembly" }
}
]
},
"transformations": {
"count": 1,
"truncated": false,
"items": [
{
"targetDeclaration": { "id": "M:App.Orders.Repository.Save(App.Customer)", "kind": "Method" },
"description": "Wrapped by advice(s) OnEntry",
"order": 2
}
]
},
"linesOfCodeAvoided": 2
}
]
}
}
The agent learns that the Log aspect applies to Save because of a multicast attribute on the assembly, which the source of Save does not show.
We designed the commands for agents first:
- JSON by default, with a stable schema.
--format textis for people. - OData queries.
listfilters aspect classes, aspect instances, transformations and declarations with$filterexpressions, such as--where "aspectClass/shortName eq 'Log'". - Output that fits in a context window. Lists are capped and summarized by namespace, and each truncated list gives the command that lists the rest.
batchruns several queries over one load of the projects, several times faster than separate calls.- Backward compatible. The commands read projects built with PostSharp 2023.0 to 2026.0, on Windows, Linux and macOS.
Available from 2027.0.7-preview, in the PostSharp.Tool global tool:
dotnet tool install -g PostSharp.Tool --prerelease
See Inspecting How Aspects Were Applied.
Documentation of Every Build Message
The new Errors and Warnings reference has one article per message code, such as PS0215, with its cause and how to fix it. An agent that reads the message and then its article fixes the code instead of silencing the message.
Available from 2027.0.5-preview.
Aspect Test Framework
The PostSharp.Testing.AspectTesting package, based on xunit.v3, is the framework we use to test PostSharp itself.
- One file, one test. Each source file is compiled, woven in an assembly of its own, verified with ILVerify, and run.
- Expected files. The test compares the output of the program and the messages of its build with files stored next to it, so a test can expect a build error.
- Snapshots of the woven code. With
@CompareTransformedCode, the framework decompiles the woven code to C# and compares it with a.t.csfile.
A test applies the aspect and calls the method:
public static class Calculator
{
[Log]
public static int Divide( int a, int b ) => a / b;
}
public static class Program
{
public static void Main()
{
Calculator.Divide( 10, 2 );
try
{
Calculator.Divide( 1, 0 );
}
catch ( DivideByZeroException )
{
}
}
}
It passes when the program writes the expected output:
Entering Divide(10, 2).
Divide returned 5.
Entering Divide(1, 0).
Divide failed: Attempted to divide by zero.
Available from 2027.0.5-preview. See Testing Aspects with the Aspect Test Framework.
Try It
An agent writes boilerplate fast, but someone still reads every line it writes. An aspect keeps the pattern in one place, and the compiler applies it deterministically at every build, whoever wrote the code.
These features are in preview releases, which are not supported in production. See What’s New in PostSharp 2027.0 for the rest of the release, and tell us how your agent did on GitHub.
Happy meta-programming with PostSharp!