These are some helpful tips and new features when upgrading to MonoGame 3.5.
Many of our users will have been running on the older stable release of MonoGame. With MonoGame 3.5 there are a few new features which you can take advantage of.
- Cross platform assembly resolution
- Upgraded to .net 4.5
Cross platform assembly resolution
Getting the right assemblies was always a pain on Mac and Linux. MonoGame 3.5 fixes that. So the same "File->New" project file will now work on all the platforms without any hacks or changes. If you want to upgrade your existing projects to take advantage of this use the following procedure.
- At the top of your .csproj Immediate after the
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />This will import the new .props file which defines the
$(MonoGameInstallDirectory) msbuild property.
- If you have declarations for
<MonoGameInstallDirectory> in your csproj remove them.
- Make sure the
<MonoGamePlatform> property is set to the correct platform. If you were targeting WindowsGL you should change over to using the DesktopGL platform and assemblies as this will help you target Linux and Mac.
- Change your Assembly HintPath values from
$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\<platform>\MonoGame.Framework.dllIf you are using the MonoGame OpenTK/NVorbis you will need to update this HintPaths as well.
- Make sure your import the content builder targets at the bottom of the project (just above the final
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
Alternatively take a look at the project templates in the MonGame Repository
Upgraded to .net 4.5
One of the other major changes is that all the MonoGame assemblies have been upgraded to .net 4.5. This might be a breaking change for some of you but the fix is easy. Simply upgrade your project to .net 4.5.
.net 4.5 was released in 2012 so it was time to upgrade. It also paves the way for using .net Core in the future.
This should probably explain the changes to the platforms so that the user can figure out what the “correct” platform is. i.e. WindowsGL => DesktopGL
Oh, and you forgot to mention that the
Content.mgcb files need to be updated as well with the new platforms.
If the file is opened with the Pipeline Tool it will autochange “WindowsGL” or “Linux” to “DesktopGL” on the next save.
Also the Content.mgcb platform is disregarded when compiling from VS/XS/MD with .targets file.
@harry-cpp Interesting. I didn’t know that, which is all the more reason to add it to the documentation.
If you are using the auto content build you can shared the Content.mgcb files between ALL the projects. So the /platform setting becomes irrelevant as it will be provided on the command line by the build .targets.
This sounds awesome but I’m not exactly sure what you mean. Is there any documentation or an example of how to do this somewhere?
if you have the Content.mgcb file in a say top level Content folder and then just Link to that single file from all the projects that should do the trick. Just make sure it has “MonoGameContentReference” as a build action.
in the csproj you end up with something like
With the 3.5 system that will auto build on Windows, Linux and Mac. I tend to only use the Pipeline tool for adding/removing items. You can leave the /platform in the Content.mgcb file as that will be overridden by the command line that the .Builder.targets file runs.
Alternatively just use a Shared Project. As that now includes a Content.mgcb file. So you can remove the ones in the projects. The only down side with that is there is a bug in VS Shared projects where the Content.mgcb file does not show up but its there in the .projitems file.
Hello! In the update to Net 4.5 a few features I used were broken. One of which was my way of testing if a variable is equal to nothing. I used to use the isNothing() function but now it returns false every time even if the object has nothing assigned to it. Is there a new way to do this? Thanks!
What you said there is like saying “My PC isn’t working, it’s not starting, help”… provide more information…
Sorry about that I solved the issue, it turned out to be something unrelated.