I have just suffered the dreaded MGFX effect was built for a different platform! error while using a shared library project along with a WindowsDX app project. None of the solutions I found on this site solved this issue so I wanted to post my solution here for the benefit of others.
It’s pretty common to use a shared library project to hold your code and content for your cross-platform game and then have an app project for each platform you want to release onto. However out-of-the box you will get the error while loading an effect and this is because the effect compiler is platform-specific so you cannot allow the shared library project to build the content.
The key to solving the error is:
- Remove the
MonoGame.Content.Builder.Task
nuget package from the shared library project. - Remove the
Content
folder from the app projects. - Hack the app projects
.csproj
files to reference theContents
folder in the shared library, by adding thisItemGroup
tag:
<ItemGroup>
<MonoGameContentReference Include="..\SharedLibraryProject\Content\Content.mgcb" />
</ItemGroup>
This should solve your problems. I have tested this with WindowsDX and DesktopGL app projects.