Improving Build Times with Monogame By Removing MonoGame.Content.Builder.Task
September 1, 2025
I’m starting to learn Monogame and one of the initial aspects which I found incredibly frustrating was its build times (~10 seconds even with no changes to the code).
After doing a bit of research,
I found that the Content Pipeline was the culprit. All the Content Pipeline did during the
build phase was convert asssets into .xnb
files and then copy them into the build
directory.
To start, I manually built the .xnb
files using the MGCB GUI which took less than a second. Then, I copied the kb-sized .xnb
files into the main build folder.
Now knowing this is all its doing during its build, it doesn’t make sense why the build time is taking ~10 seconds to complete.
Therefore I decided to build the assets before building and then copy the files manually on project build. Here's what I did:
- Remove the line
<PackageReference ... Include="MonoGame.Content.Builder.Task" ... />
from the.csproj
file
This will remove the project’s build step to build the .xnb
files and copy them into the
build directory (culprit of slow down during build step).
- Adding this line to the end of my
.csproj
file:
<ItemGroup>
<Content Include="Content\**\*.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
This will copy all of the .xnb
files in the Content directory of the project to the Content
directory of the final build, along with their directories which allows us to not change any of our
preexisting Content.Load
code.
- Editing the ‘OutputDir’ property of my ‘Content’ folder in the MGCB Editor to ‘.’
Before this change, building any assets will put them into a separate directory, making copying to the final build directory a bit cumbersome.
Now the .xnb
files will be beside their respective asset which makes it easier to copy over
to the build directory since it mimicks the same file structure.
- Run ‘Build’ in the MGCB Editor
This will generate .xnb
for every asset in your Content
directory.
Be sure to run this any time new assets are added or edited to your project from now on.
Now when I run my project on VS Code, my project loads way faster (~10 seconds => ~1 second). Hooray!🎉