Introduction Link to heading

Like many developers, my approach to software development has changed a lot with the rise of AI. However, whenever I am using a library, I notice that the quality of AI Coding Agents drops. Deprecated or old ways of working are used, code is generated that doesn’t flow nicely with the code around it, etc.

But the main problem is that often, the model just doesn’t really know what to do with the library. For example, let’s say you installed a library to help you write better tests for a specific part of your system. In my case, I was using Mockly by Dennis Doomen to make testing HttpClient code easier. But even though I installed that library, the agent didn’t use it, opting instead for a more verbose technique.

This makes sense. The dataset of the model probably doesn’t contain the latest information about the library. Another reason is that AI tries to write code similarly to existing code, so the more you use agents to write code, the more “incorrect” code is generated and the (new version of the) library gets ignored.

In this post, I’ll discuss several approaches I have found helpful to deal with this problem. But most importantly, I want to talk about a powerful concept I’ve not seen a lot of people talking about, which is shipping Agent Skills together with your library. I saw Daniel Cazzulino talking about this method on Twitter for the StructId library, and I discussed it with Mockly’s maintainer who then adopted it too. Since then, my agents have gotten noticeably better!

Here’s the part I find most exciting, and the reason for the title: in .NET, you can ship that skill inside the NuGet package itself. When a developer adds your library, the skill installs into their repository automatically. No plugin to discover, no extra command, nothing to remember. We’ll build up to that, but first let me cover what a library consumer can reach for today.

What's an Agent Skill?
If you’re unfamiliar with Agent Skills, they are a way to teach AI coding agents how to perform a specific task. Basically, a skill is just a folder with a Markdown file (and optionally some scripts or extra files) that contains focused instructions the agent can load on demand.
This isn't just useful for .NET!
This post covers the .NET ecosystem, but the concepts apply to other languages and ecosystems too. If you get it working elsewhere, I’d love to read your write-up.

Teaching Agents About Your Dependencies Link to heading

As a consumer, you have a few ways to give an agent better information about a library you’ve installed. Each one helps, and each has a catch:

ApproachWhat it doesWhy it’s not enough
Context7Indexes a library’s docs and serves them to the agentDocs can be stale or missing (it has nothing for Mockly), it eats a lot of context, and you’re trusting a 3rd party to inject instructions into your agent
AGENTS.md rulesTell the agent to prefer installed libraries, or to web search their docsManual to maintain, and the web searches make the agent slower and burn tokens
dotnet-inspectDecompiles the library so the agent can read its real API (also bundled with Aspire’s Agent Integrations)Slow; most tasks don’t need a full decompile
Write a skill yourselfA focused skill the agent loads when it touches the libraryWorks well, but every consumer writes and maintains their own copy

That last row is the clue. If a skill is the right tool, why should every consumer write the same one? The library author already knows how their library should be used, so they can write the skill once and everyone shares a single definition. But how do you ship it?

One option is the plugin systems of agents like GitHub Copilot and Claude Code. But that doubles the work: the consumer installs the library and the plugin, and they can forget the plugin or never learn it exists.

There’s a better way.

Shipping Agent Skills Together With Your Library Link to heading

If a library author already knows how their library should be used by an agent, why should that knowledge live in a separate plugin you have to find and install? It should come along with the package. When you add the library, your coding agent immediately has the right instructions. No web search, no decompilation, no separate plugin to remember.

Libraries already ship human-readable READMEs for developers. This is the same idea, aimed at AI coding agents instead.

So how does this work? You pack a SKILL.md file into your library, together with instructions on where the build/install system should store the skill. In .NET, we’d use a .targets file in the package’s build folder.

If you’re not a .NET developer: a NuGet package is the standard way to distribute .NET libraries, and a .targets file is an MSBuild file that can run extra steps during a build. Here, the extra step is conceptually simple: copy the Agent Skill to the right place in the repository that’s consuming your library.

Here’s what the package looks like, conceptually:

YourLibrary.nupkg
|- lib/...
|- build/YourLibrary.targets
+- skills/your-library/SKILL.md
+- skills/your-library/.gitignore

Your project file (*.csproj) tells NuGet to include those files in the package:

<ItemGroup>
  <!-- The Agent Skill with usage instructions for your library -->
  <None Include="AgentSkill/SKILL.md" Pack="true" PackagePath="skills/your-library/SKILL.md" Visible="false" />
  <!-- Keeps the copied skill out of the consumer's git repository, so package updates don't cause changes in git.
       It's renamed as it's packed, because a file called .gitignore here would hide SKILL.md from your own repository. -->
  <None Include="AgentSkill/skill.gitignore" Pack="true" PackagePath="skills/your-library/.gitignore" Visible="false" />

  <!-- Instructions for the build system to copy the skill into the consumer's repository -->
  <None Include="build/YourLibrary.targets" Pack="true" PackagePath="build/YourLibrary.targets" Visible="false" />
</ItemGroup>

Then the .targets file runs during the build and copies both the skill and a .gitignore into the consumer’s repository, in .agents/skills (GitHub Copilot, Codex and other agents) and .claude/skills (Claude Code). The repository root is the nearest folder above the project that contains .git. It doesn’t copy anything on CI, in IDE design-time builds, outside a git repository, or when the repository root is your home folder:

<Project>

  <!--
    Installs the agent skill (SKILL.md) into the consuming repository, so that
    coding agents working in it read guidance which matches the installed package version.

    This file ships in build/ rather than buildTransitive/, so it only runs in projects which
    reference the package directly.

    To opt out, set either property in the project or Directory.Build.props:
      <YourLibraryAgentSkill>false</YourLibraryAgentSkill>          (this package only)
      <EnableEmbeddedAgentSkills>false</EnableEmbeddedAgentSkills>  (every package that honours it)

    To choose where it is installed, declare YourLibraryAgentSkillDestination items, each a
    skills directory relative to the repository root. Declaring any replaces the defaults.

    Change "YourLibrary" to the name of your library.
  -->

  <PropertyGroup>
    <_YourLibrarySkillSource>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', '..', 'skills', 'your-library'))</_YourLibrarySkillSource>

    <!-- The repository root is the nearest directory above the project containing .git. In a
         normal checkout .git is a directory, found through .git/HEAD. In a worktree or a
         submodule it is a file. If both exist, the longer (nearer) path wins. -->
    <_YourLibraryGitDirRoot>$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '.git/HEAD'))</_YourLibraryGitDirRoot>
    <_YourLibraryGitFileRoot>$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '.git'))</_YourLibraryGitFileRoot>
    <_YourLibraryRepoRoot>$(_YourLibraryGitDirRoot)</_YourLibraryRepoRoot>
    <_YourLibraryRepoRoot Condition="'$(_YourLibraryGitFileRoot)' != '' and $(_YourLibraryGitFileRoot.Length) &gt; $(_YourLibraryGitDirRoot.Length)">$(_YourLibraryGitFileRoot)</_YourLibraryRepoRoot>

    <!-- A home directory kept in git (for dotfiles) is not a repository root for this purpose:
         ~/.claude/skills is where Claude Code looks for skills which apply to every project. -->
    <_YourLibraryRepoRootIsHome>false</_YourLibraryRepoRootIsHome>
    <_YourLibraryRepoRootIsHome Condition="'$(_YourLibraryRepoRoot)' != '' and '$(HOME)' != '' and '$([MSBuild]::NormalizeDirectory($(_YourLibraryRepoRoot)))' == '$([MSBuild]::NormalizeDirectory($(HOME)))'">true</_YourLibraryRepoRootIsHome>
    <_YourLibraryRepoRootIsHome Condition="'$(_YourLibraryRepoRoot)' != '' and '$(USERPROFILE)' != '' and '$([MSBuild]::NormalizeDirectory($(_YourLibraryRepoRoot)))' == '$([MSBuild]::NormalizeDirectory($(USERPROFILE)))'">true</_YourLibraryRepoRootIsHome>

    <!-- A project with several target frameworks runs one inner build per framework, often in
         parallel, and each would copy the same files at the same moment. Only the build for the
         first framework listed copies them. -->
    <_YourLibraryFirstTargetFramework Condition="'$(TargetFrameworks)' != ''">$(TargetFrameworks.Split(';')[0].Trim())</_YourLibraryFirstTargetFramework>
  </PropertyGroup>

  <Target Name="_YourLibraryInstallAgentSkill"
          BeforeTargets="PrepareForBuild"
          Condition="'$(YourLibraryAgentSkill)' != 'false' and '$(EnableEmbeddedAgentSkills)' != 'false' and '$(DesignTimeBuild)' != 'true' and '$(_YourLibraryRepoRoot)' != '' and '$(_YourLibraryRepoRootIsHome)' != 'true' and Exists('$(_YourLibrarySkillSource)SKILL.md')">

    <!-- Nothing reads the skill during a CI build, so it is never installed there. -->
    <PropertyGroup>
      <_YourLibraryInstall>true</_YourLibraryInstall>
      <_YourLibraryInstall Condition="'$(ContinuousIntegrationBuild)' == 'true' or '$(CI)' == 'true' or '$(CI)' == '1' or '$(GITHUB_ACTIONS)' == 'true' or '$(TF_BUILD)' == 'true' or '$(GITLAB_CI)' == 'true'">false</_YourLibraryInstall>
      <_YourLibraryInstall Condition="'$(_YourLibraryFirstTargetFramework)' != '' and '$(TargetFramework)' != '$(_YourLibraryFirstTargetFramework)'">false</_YourLibraryInstall>
    </PropertyGroup>

    <!-- Defaults are added here rather than at evaluation time, because this file is imported
         after the consumer's project body: a Remove there would run before these were added. -->
    <ItemGroup Condition="'@(YourLibraryAgentSkillDestination)' == ''">
      <YourLibraryAgentSkillDestination Include=".agents/skills" />
      <YourLibraryAgentSkillDestination Include=".claude/skills" />
    </ItemGroup>

    <ItemGroup>
      <_YourLibrarySkillFile Include="@(YourLibraryAgentSkillDestination->'$(_YourLibraryRepoRoot)/%(Identity)/your-library/SKILL.md')"
                             Source="$(_YourLibrarySkillSource)SKILL.md" />
      <_YourLibrarySkillFile Include="@(YourLibraryAgentSkillDestination->'$(_YourLibraryRepoRoot)/%(Identity)/your-library/.gitignore')"
                             Source="$(_YourLibrarySkillSource).gitignore" />
    </ItemGroup>

    <!-- A plain copy: hardlink and symlink options would tie the consumer's file to the NuGet
         package cache, so editing it would change the cache (dotnet/msbuild#8273). -->
    <Copy SourceFiles="@(_YourLibrarySkillFile->'%(Source)')"
          DestinationFiles="@(_YourLibrarySkillFile)"
          SkipUnchangedFiles="true"
          Condition="'$(_YourLibraryInstall)' == 'true'" />
  </Target>

</Project>

And after building, the consuming repository ends up with something like this:

your-repo/
|- src/
|- .agents/
|  +- skills/
|     +- your-library/
|        +- SKILL.md
|        +- .gitignore
|- .claude/
|  +- skills/
|     +- your-library/
|        +- SKILL.md
|        +- .gitignore
+- AGENTS.md

The .gitignore is there on purpose. It keeps the generated files out of source control, so consumers don’t get a noisy diff every time the package updates its skill. It ignores everything in its folder, itself included, and can contain the following:

# This directory is written by the YourLibrary NuGet package when you build, and is
# refreshed whenever the package is updated. It ignores everything in it, this file included,
# so nothing here shows up in git.
#
# To stop the package writing it, set either property in your project or Directory.Build.props:
#   <YourLibraryAgentSkill>false</YourLibraryAgentSkill>          (this package only)
#   <EnableEmbeddedAgentSkills>false</EnableEmbeddedAgentSkills>  (every package that honours it)
*
Want to learn more?
Take a look at Mockly, StructId and OwaspHeaders.Core for real implementations you can copy and learn from. OwaspHeaders.Core also has a page for consumers that explains what gets written, when it doesn’t, and how to opt out.
Let's agree on something!

If you add this to your package, please honour a shared opt-out property: EnableEmbeddedAgentSkills, defaulting to true, so a consumer can turn the copying off for every package from their project or Directory.Build.props like this:

<PropertyGroup>
  <EnableEmbeddedAgentSkills>false</EnableEmbeddedAgentSkills>
</PropertyGroup>

Today these properties are ad hoc. Mockly, for example, currently uses <MocklySkill>false</MocklySkill>. If the technique catches on and every library names its toggle differently, consumers will be stuck learning a new property per package. One shared name avoids that, so I’m proposing EnableEmbeddedAgentSkills. A package-specific property next to it is fine, like OwaspHeadersCoreAgentSkill in OwaspHeaders.Core, as long as the shared one works too.

Also, don’t forget to advertise this feature in your README!

Finishing up Link to heading

I am very curious what you think about this approach. I hope it takes off. Perhaps it already has, though I haven’t seen this in the .NET space, except for Aspire and the libraries I mentioned in this post. I am happy to be proven wrong.

If you decide to add this to your project, feel free to contact me and I’ll add your library to this post! Restoring the comment section will still take some more time.

Thanks for reading! I dedicate this post to my soon-to-be-wife, whom I will marry in just a few days on Saturday (2026-06-27). ❤️


Did you enjoy this post? Buy Me a Coffee at https://ko-fi.com/stenbrinke.nl