Search code examples
msbuildnuget

Multiple BeforeBuild targets


I want to create two distinct nuget packages in order to make some prebuild stuff on my project. The custom target files associated to the NuGet packages have both a BeforeBuild Target:

<Target Name="BeforeBuild">
   <Exec Command='...' />
</Target>

I noticed that the BeforeBuild target get executed just once, this sounds correct but in my scenario, where I want two pre build steps added by packages, how the problem could be solved?

Thanks


Solution

  • You should define multiple differently named target that hook into the build phase (using the BeforeTargets hook) and not overwrite the BeforeBuild target:

    <Target Name="MyCustomTarget" BeforeTargets="BeforeBuild">
       <Exec Command='...' />
    </Target>
    

    Refer to the Target build order documentation for more details on the execution order.