Integrate files generated during the build process into MSBuild item groups to ensure they are compiled, copied, or cleaned correctly.
- GitHub stars
- 5,942
- Files
- 1
- Last commit
- Nov 11, 2026
- License
- MIT
- Allowed tools
- —
What does the including-generated-files skill do?
including-generated-files integrates files generated during the build process into MSBuild item groups to ensure they are compiled, copied, or cleaned correctly.
Summary generated from the skill's SKILL.md.
About the including-generated-files skill
Integrating files created during a build process into MSBuild item groups is what this skill enables for developers facing compilation or output issues. It is designed for users whose build targets produce source, content, or other physical files that the build system fails to recognize, compile, or clean up. This happens because MSBuild evaluates globs during the evaluation phase before generated files actually exist on disk.
An agent should load this skill when a build target creates artifacts that are missing from the final output or are not being captured by standard globbing patterns. The skill provides specific patterns for using $(IntermediateOutputPath) to ensure path reliability and instructs on adding files to Compile and FileWrites item groups. It distinguishes between non-code files, which should use BeforeBuild timing, and source files, which require BeforeTargets="CoreCompile;BeforeCompile" to ensure they are available before the compiler runs.
What an agent can do with it
- 1Fixing uncompiled generated source filesAn agent can help resolve issues where .cs files created during a build are not being included in the compilation process.
- 2Ensuring proper cleanup of build artifactsA developer can use this to prevent stale files from accumulating by registering generated files for the clean target.
- 3Including non-code files in outputUse this to ensure configuration or data files generated during a build are correctly copied to the output directory.
- 4Correcting globbing misses in targetsThis helps when standard file patterns fail to capture files that are only created during the execution phase.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the including-generated-files skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the including-generated-files skill in Plugin
/plugin marketplace add dotnet/skills /plugin install dotnet-msbuild@dotnet-agent-skills
Install the including-generated-files skill in Claude Code
~/.claude/skills/including-generated-files/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files ~/.claude/skills/including-generated-filesInstall the including-generated-files skill in Claude Code (project)
.claude/skills/including-generated-files/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files .claude/skills/including-generated-filesInstall the including-generated-files skill in Codex
~/.agents/skills/including-generated-files/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files ~/.agents/skills/including-generated-filesInstall the including-generated-files skill in Gemini CLI
~/.gemini/skills/including-generated-files/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files ~/.gemini/skills/including-generated-filesInstall the including-generated-files skill in Claude.ai
npx degit dotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files including-generated-files && zip -r including-generated-files.zip including-generated-files # claude.ai → Customize → Skills → + → Create skill → Upload a skill → including-generated-files.zip
Automated checks
Ran Nov 15, 2026Full report →Passed our automated checks. That is not a security audit: read the scripts before you let an agent run them. How checks work
- Source repository linked and reachabledotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files is public and reachablegithub.com/dotnet/skills/tree/HEAD/plugins/dotnet-msbuild/sk ↗Pass
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit 2026-11-11github.com/dotnet/skills/commits ↗Pass
- No download-and-run or credential theft in scriptsNo scripts in the skill folderPass
- No hidden instructions in SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/dotnet/skills/blob/HEAD/plugins/dotnet-msbuild/sk ↗Pass
- Pre-approved tools are scopedNo pre-approved tools; the agent asks before using onegithub.com/dotnet/skills/blob/HEAD/plugins/dotnet-msbuild/sk ↗Pass
- SKILL.md follows the Agent Skills formatValid name and description; says when to use it; 136 linesgithub.com/dotnet/skills/blob/HEAD/plugins/dotnet-msbuild/sk ↗Pass
SKILL.md
View on GitHubIncluding Generated Files Into Your Build
Overview
Files generated during the build are generally ignored by the build process. This leads to confusing results such as:
- Generated files not being included in the output directory
- Generated source files not being compiled
- Globs not capturing files created during the build
This happens because of how MSBuild's build phases work.
Quick Takeaway
For code files generated during the build - we need to add those to Compile and FileWrites item groups within the target generating the file(s):
<ItemGroup>
<Compile Include="$(GeneratedFilePath)" />
<FileWrites Include="$(GeneratedFilePath)" />
</ItemGroup>
The target generating the file(s) should be hooked before CoreCompile and BeforeCompile targets - BeforeTargets="CoreCompile;BeforeCompile"
Why Generated Files Are Ignored
For detailed explanation, see How MSBuild Builds Projects.
Evaluation Phase
MSBuild reads your project, imports everything, creates Properties, expands globs for Items outside of Targets, and sets up the build process.
Execution Phase
MSBuild runs Targets & Tasks with the provided Properties & Items to perform the build.
Key Takeaway: Files generated during execution don't exist during evaluation, therefore they aren't found. This particularly affects files that are globbed by default, such as source files (.cs).
Solution: Manually Add Generated Files
When files are generated during the build, manually add them into the build process. The approach depends on the type of file being generated.
Use $(IntermediateOutputPath) for Generated File Location
Always use $(IntermediateOutputPath) as the base directory for generated files. Do not hardcode obj\ or construct the intermediary path manually (e.g., obj\$(Configuration)\$(TargetFramework)\). The intermediate output path can be redirected to a different location in some build configurations (e.g., shared output directories, CI environments). Using $(IntermediateOutputPath) ensures your target works correctly regardless of the actual path.
Always Add Generated Files to FileWrites
Every generated file should be added to the FileWrites item group. This ensures that MSBuild's Clean target properly removes your generated files. Without this, generated files will accumulate as stale artifacts across builds.
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)my-generated-file.xyz" />
</ItemGroup>
Basic Pattern (Non-Code Files)
For generated files that need to be copied to output (config files, data files, etc.), add them to Content or None items before BeforeBuild:
<Target Name="IncludeGeneratedFiles" BeforeTargets="BeforeBuild">
<!-- Your logic that generates files goes here -->
<ItemGroup>
<None Include="$(IntermediateOutputPath)my-generated-file.xyz" CopyToOutputDirectory="PreserveNewest"/>
<!-- Capture all files of a certain type with a glob -->
<None Include="$(IntermediateOutputPath)generated\*.xyz" CopyToOutputDirectory="PreserveNewest"/>
<!-- Register generated files for proper cleanup -->
<FileWrites Include="$(IntermediateOutputPath)my-generated-file.xyz" />
<FileWrites Include="$(IntermediateOutputPath)generated\*.xyz" />
</ItemGroup>
</Target>
For Generated Source Files (Code That Needs Compilation)
If you're generating .cs files that need to be compiled, use BeforeTargets="CoreCompile;BeforeCompile". This is the correct timing for adding Compile items — it runs late enough that the file generation has occurred, but before the compiler runs. Using BeforeBuild is too early for some scenarios and may not work reliably with all SDK features.
<Target Name="IncludeGeneratedSourceFiles" BeforeTargets="CoreCompile;BeforeCompile">
<PropertyGroup>
<GeneratedCodeDir>$(IntermediateOutputPath)Generated\</GeneratedCodeDir>
<GeneratedFilePath>$(GeneratedCodeDir)MyGeneratedFile.cs</GeneratedFilePath>
</PropertyGroup>
<MakeDir Directories="$(GeneratedCodeDir)" />
<!-- Your logic that generates the .cs file goes here -->
<ItemGroup>
<Compile Include="$(GeneratedFilePath)" />
<FileWrites Include="$(GeneratedFilePath)" />
</ItemGroup>
</Target>
Note: Specifying both CoreCompile and BeforeCompile ensures the target runs before whichever target comes first, providing robust ordering regardless of customizations in the build.
Target Timing
Choose the BeforeTargets value based on the type of file being generated:
BeforeTargets="BeforeBuild"— For non-code files added toNoneorContent. Runs early enough for copy-to-output scenarios.BeforeTargets="CoreCompile;BeforeCompile"— For generated source files added toCompile. Ensures the file is included before the compiler runs.BeforeTargets="AssignTargetPaths"— The "final stop" beforeNoneandContentitems (among others) are transformed into new items. Use as a fallback ifBeforeBuildis too early.
Globbing Behavior
Globs behave according to when the glob took place:
| Glob Location | Files Captured |
|---|---|
| Outside of a target | Only files visible during Evaluation phase (before build starts) |
| Inside of a target | Files visible when the target runs (can capture generated files if timed correctly) |
This is why the solution places the <ItemGroup> inside a <Target> - the glob runs during execution when the generated files exist.
Relevant Links
Files in this skill
1including-generated-files skill questions
How do I install the including-generated-files skill in Claude Code?
Run npx degit dotnet/skills/plugins/dotnet-msbuild/skills/including-generated-files ~/.claude/skills/including-generated-files. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the including-generated-files skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
Why are my generated files not being compiled or included in the output?
Files generated during the execution phase do not exist during the evaluation phase, so default globs cannot find them. You must manually add them to the appropriate item groups within a target.
How do I ensure generated files are removed during a clean build?
You must add every generated file to the FileWrites item group so that MSBuild's Clean target can track and remove them.
What is the correct timing for adding generated source files to the compilation process?
Use BeforeTargets="CoreCompile;BeforeCompile" to ensure the target runs after file generation but before the compiler executes.