How exactly to use the Pipeline Tool to add assets in MonoGame 3.6 with Visual Studio 2017 in Windows

I have read many versions of how to add assets using the MONOGAME pipeline tool but NONE talk about MONOGAME 3.6 with Visual Studio 2017, at least I haven’t found anything so far.

It is not as easy as right click and select and add existing item or add new item. There are add as link, copy to folder, and then setting up parameters in visual studio etc. etc.

Corusera teaches a way of adding a new content.mgcb and going back and fourth and I couldn’t figure out why you need a new contnet.mgcb when there is one built already when you open a MONOGAME Winodws project with VS2017.

Is there someone here who can, in point form, explain how to add one png image into a graphics folder to use with a VS2017 project? That will give a head start to work with audio and fonts as only the type will vary. Point form please. I am sure this will benefit many immensly.

These articles tell you to create the Content.mgcb file if it doesn’t exist already. They assume that it doesn’t exist, for convenience (for example, if you’re using the NuGet installation of MonoGame.)

If it already exists, use the existing Content.mgcb. It’s already set up to build when you compile/run your game.

  • Right-click the Content.mgcb file in Solution Explorer
  • Click “Open With”
  • A box should come up asking you what to open it with - choose “MonoGame Pipeline Tool”.

This will pop open the MG pipeline tool GUI. Right-click in the treeview to the left, click “Add > New Folder”. Name it “graphics” or whatever you desire.

It’ll add to the tree. Right-click the new folder, click “Add > Existing Item”. Find the PNG texture you’d like to add and open it. Then, click “File > Save” in the Content Pipeline.

Then, in Visual Studio, in your game class, add a Texture2D variable to store the texture in. In LoadContent(), add

myTextureVariable = Content.Load<Texture2D>("graphics/myTexture");

Note: Replace “graphics/myTexture” with the asset path to the PNG image you added in Content Pipeline. If you added a PNG file named “smile” to the “graphics” folder, the asset path is “graphics/smile”.

You must also omit the file extension of the PNG file in the asset path - so, it’s “smile”, not “smile.png”.

Then, for good practice, in UnloadContent:

myTexture.Dispose();
myTexture = null;

to free up the RAM taken by your loaded texture.

Hopefully that helps!

1 Like

what about the xnb file? isn’t adding via the pipeline tool a way to optimze the size of graphics file for monogame? When you reference the png files directly does VS use the pngs themselves or are they
compiled to xnb files? Dont you have to add the xnb files to the Content folder in the solution explorer?

If you start your project from one of the templates that MG provides, the .mgcb file will have a build action of MonoGameContentReference. That build action will check if a rebuild is needed (i.e. new or modified content) and then copy all xnb’s to your output folder. There’s no need to add the .xnb files or source files to your project or copy them to the output folder manually.

This is explained in the docs as well: http://www.monogame.net/documentation/?page=Using_The_Pipeline_Tool
Specifically in the “Linking Content To Your Game” section.

2 Likes

Thank! That cleared a lot of things.

1 Like

Hi,

this works. :slight_smile: The graphics folder does not show up in the solution explorer pane but it builds without errors and the sprites are drawn. Still a bit weird but does the job.

Thanks,
Stephan

Thank you Watercolor Games. As a beginner I was struggling to use the Pipeline Tool without it crashing and your instructions helped.

Probably a really late reply, but…the reason the graphics folder doesn’t show up in your Solution Explorer in Visual Studio is because…it simply doesn’t need to be directly used by your solution. Only the Content.mgcb file needs to actually be in the Solution Explorer with the relevant build action. The .mgcb file contains a list of file paths to various content files in your game, and how they should be imported and processed.

So all your Visual Studio project needs to do is say “OK, MonoGame, this is a Content.mgcb file. I’ve been told to tell you to build it. Can you build it?”. MonoGame will then look at all the paths in that file, process everything into .xnb files, and copy them over to the right spot in your game’s output. That’s why Visual Studio doesn’t show your other content files - it doesn’t need to know they’re there.

But that’s also why you get some vague compiler errors in Visual Studio when MonoGame fails to process all your content. Usually I tend to build my stuff in the Pipeline GUI and get the actual error details when working with HLSL shaders.

In conclusion, it’s not Visual Studio building your content - so your content won’t show in Visual Studio as part of your solution. Instead, MonoGame keeps track of your content on its own - only you and MonoGame need to know where the files are.

Quick edit: If you really want to see your content files in the Solution Explorer, you can click the “Show all files” button - it looks like a stack of papers in the Solution Explorer’s toolbar.

1 Like

I’m having real problems loading a content file in an Android build, what am I doing wrong

trying to load a .jpg file called “abc1.jpg” its in the content root folder and compiled as well as it properties being set to “AndroidAsset”

Texture2D texture;

protected override void LoadContent()
{
  // Create a new SpriteBatch, which can be used to draw textures.
  spriteBatch = new SpriteBatch(GraphicsDevice);

// music = new Music();
// music.PlayMedia(“Folder\title”);

  string name = "abc1.jpg";
  // NOTE PROPERTIES ARE "AndroidAsset"
  texture = Content.Load<Texture2D>(name);

  // TODO: use this.Content to load your game content here
}

the commented // music section works fine, the texture causes an exception, such a simple piece of code done it a 1000 times yet building it via an android build, nada. Please Help

Paul

Where is the commented out Music code from? It’s not part of MonoGame (unless it’s something really old), so I’d be looking it what it’s doing that works.

the music code is just a class that uses “songs” if android and uses native UWP functions to get around the sharpdx.multimedia bugs

The other thing is it only seems to crash using the VS Emulator, on an actual Android device it works fine, i’m looking into the emulators now as I need to check on various devices
but if you have any ideas let me know

Paul