Textfiles as Resources

Hi,

I have written a game for Windows Desktop and now I want to port it to Windows Metro/ModernUI/WindowsStore.

My level definition are simple text files which are placed in my content directory. In my Desktop app I use things like Directory.GetFiles, File.Exists and so on.

But these seems not be available for Windows Store. What is the proper way to use textfiles as resources?

How are the text files being used? You can include them as content files and process them as such (creating xnbs) to be loaded at run time through Content.Load. If these are files that the user will add/create/acquire themselves themselves then you’ll need a native approach for the Windows 8 platform.

Building and using the textfiles as xnb would be okay for me.

But how do I have to build the textfiles with MGCB? I found nothing about building textfiles here: http://www.monogame.net/documentation/?page=MGCB

So I just added the file to my build content like this

#settigs
/platform:Windows    
# Directories
/outputDir:../Content/Windows
/rebuild
/build:level/01.txt

But I’m getting this error: …\Assets\level/01.txt: error: Failed to create importer ‘’

So, how do I have to do it right?

You need to create a content pipeline to process the txt file. In this case, you want it to simply pass through the text as is. The official MSDN documentation for XNA covers custom importers/exporters fairly well.

After that, in the MGCB file you may have noticed a sections called References that might be empty for you. In there you will need to put the path to the compiled content pipeline project dll. The syntax for this is:

/reference:\Some\Path\To\Your\Importer.dll

MGCB will then use the dll to create an instance of your importer/processor when it tries to build a content with that right extension. This is the reason for the ‘Failed to create importer’ error you are currently getting: you don’t have an importer for ‘txt’ extensions.