Question: controlling the build order
how can one ensure CGR is the first to run in the presence of multiple code generation/s in the build pipeline?
You'll probably want to add the GenerateCodeFromAttributes MSBuild target to a DependsOn property of the other generators' MSBuild target.
https://github.com/AArnott/CodeGeneration.Roslyn/blob/fd1200769415b5428fbd6c5859dbe55cf78f0b7b/src/CodeGeneration.Roslyn.Tool/build/CodeGeneration.Roslyn.Tool.targets#L15-L20
yup - that worked.
to be precise, took the following steps.
in the project/s with the attributes and the codegen classes:
- added the reference to the nuget tool package
<ItemGroup>
<PackageReference Include="CodeGeneration.Roslyn.Tool" Version="{replace with actual veetrsion used}" />
</ItemGroup>
- and the following target
<Target Name="RunCodeGenerationRoslynFirst" BeforeTargets="Build">
<CallTarget Targets="GenerateCodeFromAttributes" />
</Target>
NB: added the following to the project with the custom CGR attributes/codegens and not the other generators MSBuild target
- adding the depends on the other codegen/s would require building a custom build for its nuget package
-
BeforeTargetsfor theRunCodeGenerationRoslynFirsttask can be easily updated based on inspection of the other codegen/s default targets - this does cause the problem when makes changes to custom CGR project, would require two builds to take effect. but an easy workaround could be to have two have separate project files - one for development and the other for usage (with the above target)
if there could be a better way - do advise, else please close the ticket.
If you can share what exactly is that other generator, I could look and advise.
As is, your solution looks like a hacky one. Maybe a better one can be written.
https://github.com/AArnott/CodeGeneration.Roslyn/wiki/Features#definitions
Please use terms as defined, so I'll be able to understand you quickly.
For a quick enhancement, you could replace CallTarget, which is rarely a good idea, with DependsOn=Generate... in your custom target.