Unable to run custom MSBuild targets before/after MGCB task

Hello there!:blush:

I just updated my whole code base to the new prerealease version 3.8.0.1375-develop and now I try to implement a custom build process with MSBuild (though I am fairly new with the “targets” stuff :sweat_smile:)

According to this part of the MGCB documentation, I can use BeforeTargets="BuildContent" and AfterTargets="BuildContent" to do things before or after the MGCB process runs.

So here is what I tried in my .csproj :

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <MonoGamePlatform>Windows</MonoGamePlatform>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1375-develop" />
  </ItemGroup>

  <Target Name="MyBeforeTarget" BeforeTargets="BuildContent">
    <Message Text="MyBeforeTarget Ran"/>
  </Target>
  <Target Name="MyAfterTarget" AfterTargets="BuildContent">
    <Message Text="MyAfterTarget Ran"/>
  </Target>
  <Target Name="IncludeContent" BeforeTargets="PrepareForBuild">
    <Message Text="IncludeContent Ran"/>
  </Target>

</Project>

Unfortunately, none of these targets seem to be called as long as MonoGame.Content.Builder.Task is in the project. Only the MGCB task runs during the build and I don’t see any other message in the Build Output. Am I missing something?

Ah, the target names got changed: https://github.com/MonoGame/MonoGame/blob/develop/Tools/MonoGame.Content.Builder.Task/MonoGame.Content.Builder.Task.targets#L13

1 Like