Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Question: controlling the build order #234

Open
dszryan opened this issue Jul 16, 2020 · 4 comments
Open

Question: controlling the build order #234

dszryan opened this issue Jul 16, 2020 · 4 comments
Labels

Comments

@dszryan
Copy link

dszryan commented Jul 16, 2020

how can one ensure CGR is the first to run in the presence of multiple code generation/s in the build pipeline?

@amis92
Copy link
Collaborator

amis92 commented Jul 16, 2020

You'll probably want to add the GenerateCodeFromAttributes MSBuild target to a DependsOn property of the other generators' MSBuild target.

<Target
Name="GenerateCodeFromAttributes"
Condition=" '$(UsingCodeGenerationRoslynToolTargets)' != 'false' "
DependsOnTargets="$(GenerateCodeFromAttributesDependsOn)"
BeforeTargets="CoreCompile;PrepareResources">
</Target>

@dszryan
Copy link
Author

dszryan commented Jul 17, 2020

yup - that worked.

to be precise, took the following steps.

in the project/s with the attributes and the codegen classes:

  1. added the reference to the nuget tool package
    <ItemGroup>
        <PackageReference Include="CodeGeneration.Roslyn.Tool" Version="{replace with actual veetrsion used}" />
    </ItemGroup>
  1. 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
  • BeforeTargets for the RunCodeGenerationRoslynFirst task 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.

@amis92
Copy link
Collaborator

amis92 commented Jul 17, 2020

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.

@amis92
Copy link
Collaborator

amis92 commented Jul 17, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants