including-generated-files

Configure MSBuild targets to include build-generated files in compilation and output.

Updated Sep 22, 2026
One-click install
npx skills add https://github.com/bytecakelake/Nurse-Scheduler --skill including-generated-files-bytecakelake
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: including-generated-files
Source: https://github.com/bytecakelake/Nurse-Scheduler/tree/main/.agents/plugins/dotnet-msbuild/skills/including-generated-files
Command: npx skills add https://github.com/bytecakelake/Nurse-Scheduler --skill including-generated-files-bytecakelake

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Files generated during an MSBuild build are invisible to the rest of the build because globs expand during the evaluation phase, before execution creates them. This causes generated source files to be skipped by the compiler (CS0246 errors), generated content to be missing from the output directory, and stale artifacts to survive the Clean target. ## Core Features & Use Cases - Correct Target Timing: Choose the right BeforeTargets hook (BeforeBuild, CoreCompile;BeforeCompile, or AssignTargetPaths) based on the type of file being generated. - Item Group Registration: Add generated files to Compile, None, or Content item groups inside the generating target so they are compiled or copied to output. - Clean Support: Register every generated file in the FileWrites item group so the Clean target removes it, and use $(IntermediateOutputPath) instead of hardcoded obj/ paths. - Use Case: A custom build task generates a .cs file at build time, but the compiler reports CS0246 for a type that should exist. Hook the target with BeforeTargets="CoreCompile;BeforeCompile" and add the file to Compile and FileWrites so it compiles and cleans correctly. ## Quick Start Fix my MSBuild target so the .cs file it generates during the build is actually compiled and removed by Clean.

Frequently Asked Questions about including-generated-files

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I include generated files in an MSBuild compilation?▼

Add the generated file to the Compile item group inside the target that creates it, and hook that target with BeforeTargets="CoreCompile;BeforeCompile". This ensures the file exists and is registered before the compiler runs.

Why are my MSBuild globs not picking up generated files?▼

Globs outside of targets expand during the evaluation phase, before any target executes, so files created during the build do not exist yet. Move the ItemGroup with the glob inside a target so it expands during the execution phase.

What BeforeTargets value should I use for generated source files?▼

Use BeforeTargets="CoreCompile;BeforeCompile" for generated .cs files added to Compile. For non-code files copied to output, BeforeTargets="BeforeBuild" works, with AssignTargetPaths as a later fallback.

How do I make MSBuild Clean remove generated files?▼

Add every generated file to the FileWrites item group inside the generating target. The Clean target uses FileWrites to know which files to delete, so unregistered files accumulate as stale artifacts.

Should I hardcode the obj folder path for generated files?▼

No, always use $(IntermediateOutputPath) as the base directory for generated files. The intermediate path can be redirected in shared output or CI configurations, so hardcoding obj\ breaks those builds.

When should I not use this approach for generated code?▼

Do not use it for C# source generators, which already integrate through the Roslyn pipeline, or for T4 design-time generation that runs inside Visual Studio. It targets custom MSBuild targets and tasks that create files during execution.