.TXT files don't work in the content manager?

Hi again, all.

I’m having another spot of bother, but this time it’s with setting up tilemaps - using SimonDarksideJay’s 2D platformer code samples (found here) was going well and without any errors until it came time to start implementing tilemaps.

It’s possible I missed something that makes adding .TXT files possible since I’m still very new to Monogame and making this 2D platformer for a university assignment, but I’ve added a folder to the content manager called Levels, and inside are three .TXT files titled {0}, {1} and {2} respectively. None of this is changed from the sample code so, that should be fine.

The issue comes when I then try to run the code - I get these error messages:

Error MSB3073 The command “dotnet C:\Users\Squid.nuget\packages\monogame.content.builder.task\\build\…\tools\netcoreapp3.1\any\mgcb.dll /quiet /@:“G:\Work Related Learning\WRLPlatformer\Content\Content.mgcb” /platform:Windows /outputDir:“G:/Work Related Learning/WRLPlatformer/Content/bin/Windows/Content” /intermediateDir:“G:/Work Related Learning/WRLPlatformer/Content/obj/Windows/Content” /workingDir:“G:/Work Related Learning/WRLPlatformer/Content/”” exited with code 4.

Couldn’t find a default importer for ‘G:/Work Related Learning/WRLPlatformer/Content/Levels/{2}.txt’!
Couldn’t find a default importer for ‘G:/Work Related Learning/WRLPlatformer/Content/Levels/{1}.txt’!
Couldn’t find a default importer for ‘G:/Work Related Learning/WRLPlatformer/Content/Levels/{0}.txt’!

Is there any way I can get the engine to recognise .TXT files the way it apparently does in the sample code, or do I need to use a different file type?

Any help would be massively appreciated (and sorry if I seem hopeless, most posts covering this issue on the internet lead to 404’d webpages! :sweat_smile:)

Additional information:
I’m using the most recent release, NuGet 3.8 on Visual Studio 2019.
The project I set up is “for the Windows desktop using DirectX” and I’m on Windows 10 x64.
I’m testing all this on my laptop, and it’s a computer-only project so the gamepad/touch features in the sample code have been deleted / are not included in my project.

MonoGame Content Manager is used to take engine-unfriendly assets (like PNGs) and “compile” them (or “import/build/etc”) them into MonoGame assets (*.xnb files and such).

So, what you’re running into here is that you’re trying to feed a file to the Content Manager that it doesn’t have a default way to process. Because it’s just a simple text file, and presumably you don’t want it to do anything to it.

Solution: Just set the build action to “Copy” and when it builds all your content it will just dump that text file in there with the built assets

Example of a text file in your .mgcb file, as opposed to something like a sound effect.

#begin textFile.txt

#begin sounds/airBlast.wav

This worked perfectly, thank you so much!!


When I do this, ContentManager.Load will not work anymore and throws an exception saying “Could not find file C:\path\to\content\text.txt.xnb”. It seems like the Load method is still trying to find the xnb file for the text asset even though it is copied. How would I access the text file if I set the build action to Copy? Do I just open it like any other file in c#?

Yeah, just a simple System.IO.File.ReadAllLines is all you need.

1 Like

That’s not much of a solution. If I wanted to just read the file, I wouldn’t spend time putting it into the bundle in the first place. Is there a real solution here short of creating an importer and processor?

If you want to compile the txt into an xnb file and load it through the Content.Load method then yes, you will need to create an importer for it. The thing to understand, though, is that that’s a horribly convoluted way of doing it.

Despite being the default method of importing content in Monogame, the Content Pipeline is not a lightweight, user-friendly asset importer, nor is it meant to be. It’s a heavyweight compiler whose purpose is to convert assets into the binary xnb format.

The primary advantage of this format as I understand it is that it’s easy to stream into RAM, which cuts down on loading times. A secondary advantage/disadvantage (depending on your perspective) is that the assets original format is obscured and can’t be loaded by end users. The Content Manager also does not bundle items. Unless you write custom processors, you’ll end up with just as many xnb files as you had original assets.

1 Like