1
\$\begingroup\$

I am coming straight from XNA and I installed the latest version of MonoGame today (2015-12-22) for Visual Studio 2015 Community. I created a project from the windows Project template.

project

I right click the content folder and add a png-file. I compile without error but it stops during runtime because it can't find the content file. My solution look like this

Solution

Game1.cs look like this:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace homer
{
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        private Texture2D simpson;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            simpson = Content.Load<Texture2D>(@"Images/Homer");
        }

        protected override void UnloadContent(){ }

        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            spriteBatch.Draw(simpson, new Vector2(200, 100), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

The problem I encounter is that MonoGame do not make xnb-files from the png and put it in my output folder. I tried to copy the file manually from a compiled XNA project to my MonoGame debug folder and it worked. I have done nothing but create a project from the template and trying to load an image. What do I need to do to make MonoGame compile xnb-files for me. It also runs if I change "Do not copy" to "Copy always" but that is not optimal for runtime as I understand it. Also, I don't want it to be too easy for the users to doodle in the graphics.

Content.mgcb look like this

#----------------------------- Global Properties ----------------------------#

/outputDir:bin/Windows
/intermediateDir:obj/Windows
/platform:Windows
/config:
/profile:Reach
/compress:False

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Open the Content.mgcb file with the ContentPipeline tool. From there you can add the .png file and the content will be build for you.

The content pipeline tool is located on my machine in: "C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\Pipeline.exe"

\$\endgroup\$
7
  • \$\begingroup\$ Worked like a charm. Do I need to do this for every single file in a project? It feels a little redundant to having to add every file twice, first in visual studio and then in the pipeline editor. \$\endgroup\$ Dec 22, 2015 at 20:34
  • 1
    \$\begingroup\$ You can add files in the pipeline tool (even create folders to organise content). So instead of adding them to your project, add them here in stead. \$\endgroup\$
    – Felsir
    Dec 22, 2015 at 20:36
  • 1
    \$\begingroup\$ I tried to add things just in the Pipeline editor but that do not work for me. I must add it both in the project and in Pipeline for it to get to the output folder. \$\endgroup\$ Jan 1, 2016 at 23:13
  • \$\begingroup\$ That's weird. The pipeline builds the content. The only thing I could think of is that the builder otherwise has no access to the files. When you add something in the pipeline tool that is not in your project folder, it should ask if the pipeline needs to copy the content to the folder. Does that happen in your case? \$\endgroup\$
    – Felsir
    Jan 2, 2016 at 14:15
  • \$\begingroup\$ The Pipeline asks me if it should, and does, copy to the project folder. But it do not show up in the project explorer until I add it in visual studio. It works if I add things in both places. \$\endgroup\$ Jan 2, 2016 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .