Target the XNA framework in ordinary Visual Studio 2012 project

爱⌒轻易说出口 提交于 2019-12-24 03:38:16

问题


I have a C# XNA host project, with an F# client project that will contain all my functionality. It won't build because the F# project has references to mscorlib.dll and System.dll that the XNA project doesn't agree with (the actual error -- well, its really a warning that in my opinion should be an error -- is at the bottom of the post). How can I tell the F# project to target the actual XNA platform (specifically for the Xbox 360)?

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3268: The primary reference "\\vmware-host\Shared Folders\Projects\FSharp\Whirlygigs\Whirlygigs.Lib\bin\Debug\Whirlygigs.Lib.dll" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "\\vmware-host\Shared Folders\Projects\FSharp\Whirlygigs\Whirlygigs.Lib\bin\Debug\Whirlygigs.Lib.dll" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=***".
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3268: The primary reference "\\vmware-host\Shared Folders\Projects\FSharp\Whirlygigs\Whirlygigs.Lib\bin\Debug\Whirlygigs.Lib.dll" could not be resolved because it has an indirect dependency on the framework assembly "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "\\vmware-host\Shared Folders\Projects\FSharp\Whirlygigs\Whirlygigs.Lib\bin\Debug\Whirlygigs.Lib.dll" or retarget your application to a framework version which contains "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=***".

回答1:


The problem that you are having is that one of your projects is targeting the Windows versions of the .NET Framework (mscorlib, System) and one of your projects is targeting the Xbox 360 versions of the framework. And, basically, you cannot link together assemblies targeting different core frameworks.

I'm guessing that your F# project is targeting the Windows versions of the assemblies. What you need to do is get your F# project to target the Xbox 360 reference assemblies.

(Note that I've never done this myself - so my answer is just a list of things you could try.)

For your reference, these reference assemblies are installed by default to C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Xbox360\

First of all, you could try using the Portable Class Library. I've heard mixed reports about this.

The way I would probably do this is with some manual MSBuild trickery. A Visual Studio project file is an MSBuild file (which is XML). You can open it up in a text editor and play with it. You'll notice that an XNA project imports the following file:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" />

So you could try simply adding that import to your project file (and maybe some of the other XNA configuration, like <XnaPlatform>, in the appropriate place). That might do the trick.

If not, you could actually look at these files (they're at C:\Program Files (x86)\MSBuild\Microsoft\XNA Game Studio\v4.0) and try and figure out what they're using to set the path for framework assemblies. I'm not knowledgeable enough with MSBuild to say for sure.

Otherwise, you could just brute-force it. You can turn off the built-in referencing of the core frameworks by adding this to a <PropertyGroup>:

<NoStdLib>true</NoStdLib>

And then manually set the paths for each reference. So you would change this:

<Reference Include="mscorlib" />

To this:

<Reference Include="mscorlib">
  <HintPath>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Xbox360\mscorlib.dll</HintPath>
</Reference>

And so on for all the other references. I've previously had success with this last method, for doing something similar (manually changing the target framework).



来源:https://stackoverflow.com/questions/12993514/target-the-xna-framework-in-ordinary-visual-studio-2012-project

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