I followed the tutorials in the getting started section but I'm stuck at linking my content project to my main game as shown in the managing content section. I can link my content project if my main game project is just a regular monogame windows project but I can't if it's a windows store project. I get an error message saying "Unable to add a reference to project…". Is there a solution for linking content projects to window store projects?
Date: 12 May 2014 21:36
Number of posts: 4
RSS: New posts
Yeah, there is, though it's far more obnoxious than if you're using a plain old Windows application, which can make the direct link and be good.
The basic trick here is that the content project produces .xnb as output, which your game needs as input. With the "simpler" plain Windows projects, it's able to use the content project as a dependency, which then magically gets the files into a location that your game project will be able to access. Since you can't make the same link with a Windows store project (and some of the others as well) you have to do it manually. Sort of.
So the first thing is, you don't even try to link the projects like the tutorial says to. You do the following instead.
Whenever you add new content or edit the files, you have to tell the content project to rebuild. (With them linked, Visual Studio will build the dependency when it builds the main project, so it took care of this for you.) You can do that by right-clicking on the content project and choosing Build.
After this, you'll have updated .XNB (content) files created.
Now you just have to get them in the right spot.
The low-tech way of doing this is to go into the file system and just copy the files over from the bin folder in the content project over into that little folder called Content in the main game project.
Once the files are copied over, go back into Visual Studio and make sure that all of the files are included in the project. To do this, you'd right-click on the content folder and choose Add > Existing Item…. The little drop down by the bottom is limiting this to something like just .cs files by default, so you'll want to change the filter to show all files.
You then want to make sure that the files get copied to the output directory. (I would have had you just copy the files to there directly in the last step, but you can't. Every time you rebuild the game project, that gets blown away. You don't want to have to copy the files every single time you build and run your game, so don't do that.) The way to tell your project to copy these files to the output directory is to select them in the Solution Explorer and then in the Properties view, there's a Copy to Output Directory part that says "Do not copy" by default. Change it to "Copy always" so that it copies it to the output directory on build.
That should get them placed where you need them for it to load.
It's a lot of work, I know.
Now every time you modify the content, you'll want to re-build the content project, then recopy the files. (Hopefully, this is rarer than code changes.) If you've added new files (or deleted files) you'll have to add (or remove) them from under the Content folder in the main game project and change the Copy to Output Directory again.
You can actually streamline this process significantly by adding the copy commands as post-build tasks in your project. That's probably a discussion for another day. Get the content copying over manually for now, and we can talk about post-build tasks later…. :)
Hm. Also make sure that when you build your content project, you build it as a "Win8" project. I think the default is PSM (PlayStation Mobile) which is probably the worst default they could have chosen, as it's probably one of the rarer project types. (It would be better if it were smart enough to figure it out on its own.) If you don't change it, the content will be dumped into a PSM folder, whereas, you want it in the Win8 folder. Honestly, I'm not sure if there's a difference in the output, but there definitely could be.
Sorry for the late feedback but it works! Thanks alot. I followed your instructions but the program always crashed when trying to load textures so I realized I had to change the build action properties of the .xnb files to 'content' for it to work.