Search code examples
c#code-generationcsprojmsbuild-task

Msbuild step to generate c# file and then compile it


I have a .csproj named P with a custom task in it.

<UsingTask TaskName="[FullTaskName]" AssemblyFile="$(TargetPath)" />

<Target Name="[CustomTaskName]" BeforeTargets="Build">
    <[CustomTask] />
</Target>

This custom task replace the content of an included file F in P. This replacement can lead to errors in F.

However when I build P (and then run the custom task), the build pass whatever the content of F.

How to include the new content of F when building P?


Solution

  • Changing BeforeTargets="Build" to BeforeTargets="BeforeBuild" seems to be working.