Monogame Ambiguous Vector2

痞子三分冷 提交于 2020-01-16 05:08:04

问题


I am having an issue where I keep getting ambiguity errors between Monogame and XNA libraries. No matter what I do, I cannot get it to compile. I have removed XNA off my computer and yet the error still persists. The full error is:

Error   4   Argument 1: cannot convert from 'Microsoft.Xna.Framework.Vector2 [c:\Program Files (x86)\MonoGame\v3.0\Assemblies\WindowsPhone\x86\MonoGame.Framework.dll]' to 'Microsoft.Xna.Framework.Vector2'

on lines such as:

        EngineGlobal.world = new World(new Vector2(0,9.8f), false);

Does anyone have any suggestions on how to get rid of the conflict? I would like to continue to develop on monogame rather than XNA since the code will be ported into MonoGame environments on Android, iPhone, etc.

Any help is greatly appreciated!


回答1:


A bit late with my reply, but if you look at what MonoGame project templates do, you will find that there is an extra build target defined in csproj file.

In my case adding this:

<Target Name="MonoGame_RemoveXnaAssemblies" AfterTargets="ImplicitlyExpandTargetFramework">
<Message Text="MonoGame - Removing XNA Assembly references!" Importance="normal" />
<ItemGroup>
  <ReferencePath Remove="@(ReferencePath)" Condition="'%(Filename)%(Extension)'=='Microsoft.Xna.Framework.dll'" />
  <ReferencePath Remove="@(ReferencePath)" Condition="'%(Filename)%(Extension)'=='Microsoft.Xna.Framework.GamerServices.dll'" />
  <ReferencePath Remove="@(ReferencePath)" Condition="'%(Filename)%(Extension)'=='Microsoft.Xna.Framework.GamerServicesExtensions.dll'" />
  <ReferencePath Remove="@(ReferencePath)" Condition="'%(Filename)%(Extension)'=='Microsoft.Xna.Framework.Input.Touch.dll'" />
  <ReferencePath Remove="@(ReferencePath)" Condition="'%(Filename)%(Extension)'=='Microsoft.Xna.Framework.MediaLibraryExtensions.dll'" />
</ItemGroup>

to the csproj with ambigious references solved the problem.




回答2:


This kind of error is almost always to do with references. If you are absolutely certain it's not referencing XNA it could be referencing a different version of MonoGame.

Try removing all your MonoGame and XNA references from all projects and re-reference them. This includes projects that are already compiled with XNA. They may need to be recompiled.




回答3:


As far as I can tell, Farseer has been written to work on several platforms. It accomplishes this (in part) through conditional compilation.

I've noticed that several XNA types are re-defined in the Farseer solution but using the original Microsoft XNA namespace.

This normally isn't a problem because these definitions are excluded on platforms such as the XNA desktop, Windows Phone, and XBox.

This does become an issue, however, when Farseer is used with an unexpected platform: MonoGame.

To get around this I simply downloaded the source and removed the files with XNA re-definitions.

ALTERNATIVELY

If you are working with the source code you should be able to prevent these definitions from compiling by defining any one of the following Conditional Compilation Symbols:

  • XNA
  • WINDOWS_PHONE
  • XBOX
  • ANDROID

This can be done in your project's property's Build tab.

Or even better, define a MONOGAME symbol and add it to conditional compilation line:

#if !XNA && !WINDOWS_PHONE && !XBOX && !ANDROID && !MONOGAME



来源:https://stackoverflow.com/questions/15676064/monogame-ambiguous-vector2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!