Loading...
Loading...
Proper handling of files generated during the MSBuild's build process. Only activate in MSBuild/.NET build context. Use when generated files are not being included in compilation, output, or when globs aren't capturing generated files. Covers MSBuild evaluation vs execution phases, timing targets to include generated files, and ensuring generated files are tracked for incremental builds and clean.
npx skill4agent add dotnet/skills including-generated-filesCompileFileWrites <ItemGroup>
<Compile Include="$(GeneratedFilePath)" />
<FileWrites Include="$(GeneratedFilePath)" />
</ItemGroup>BeforeTargets="CoreCompile;BeforeCompile".cs$(IntermediateOutputPath)$(IntermediateOutputPath)obj\obj\$(Configuration)\$(TargetFramework)\$(IntermediateOutputPath)FileWritesFileWritesClean<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)my-generated-file.xyz" />
</ItemGroup>ContentNoneBeforeBuild<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>.csBeforeTargets="CoreCompile;BeforeCompile"CompileBeforeBuild<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>CoreCompileBeforeCompileBeforeTargetsBeforeTargets="BeforeBuild"NoneContentBeforeTargets="CoreCompile;BeforeCompile"CompileBeforeTargets="AssignTargetPaths"NoneContentBeforeBuild| 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) |
<ItemGroup><Target>